0

我正在使用第三方提供商进行信用卡付款,他们需要通过表格发布数据,但是我传递的数据来自数据库,而不是来自填写表格的用户。

目前,我通过一个使用 JavaScript 自动提交的页面来解决这个问题,但是,虽然这可行,但它看起来并不专业。有没有办法让 PHP 发布到然后加载到浏览器中的页面?

<body onload="document.form1.submit()">
<form method="post" action="https://payment.provider.com/Servlet" id="form1" name="form1" target="_top">
    <input type="hidden" name="TRANSACTION_ID" value="<?php echo $transid; ?>" />
    <input type="hidden" name="AMOUNT" value="<?php echo $amount; ?>" />
    <input type="hidden" name="TERMINAL_ID" value="T04_000000000005" />
    <input type="submit" value="Click if not redirected" name="submitButton" />
</form>
</body>

我知道 cURL 当然可以发布数据,但它需要响应。提交表单时,数据会发布到页面,但该页面随后会加载到浏览器中。发布数据后,需要将用户带到第三方提供商页面(该页面使用发布的值,因此我不能简单地进行重定向)。

4

1 回答 1

0

是的,我已经找到了解决方案。

在我发现这个解决方案的过程中,我也遇到了一个新的发现。如果您使用计时器打开新页面,Chrome 会阻止该页面。如果您使用按钮打开新页面,Chrome 不会阻止它。

这是我想出的解决方案:

/** This is the script that will redraw current screen and submit to bank. */
echo '<script>'."\n" ;
echo 'function serverNotifySelected()'."\n" ;
echo '{'."\n" ;
echo '    window.open(\'\', \'BankPaymentScreen\');'."\n" ;
echo '    document.forms[\'bank_form\'].submit();'."\n" ;
echo '    document.forms[\'server_responder\'].submit();'."\n" ;
echo '}'."\n" ;
echo '</script>'."\n" ;

/** This form will be opened in a new window called BankPaymentScreen. */
echo '<form action="https://www.sandbox.bank.com/cgi-bin/webscr" name="bank_form" method="post" target="BankPaymentScreen">'."\n" ;
echo '<input type="hidden" name="cmd" value="_s-xclick">'."\n" ;
echo '<input type="hidden" name="custom" value="'.$transaction_start.'">'."\n" ;
echo '<input type="hidden" name="hosted_button_id" value="'.$single_product->hosted_button_id.'">'."\n" ;
echo '<table>'."\n" ;
echo '    <tr>'."\n";
echo '        <td><input type="hidden" name="'.$single_product->hide_name_a.'" value="'.$single_product->hide_value_a.'">Local</td>'."\n" ;
echo '    </tr>'."\n" ;
echo '    <tr>'."\n" ;
echo '        <td>'."\n" ;
echo '        <input type="hidden" name="'.$single_product->hide_name_b.'" value="'.$single_product->hide_value_b.'" />'.$single_product->short_desc.' $'.$adj_price.' USD'."\n" ;
echo '        </td>'."\n" ;
echo '    </tr>'."\n" ;
echo '</table>'."\n" ;
echo '<input type="hidden" name="currency_code" value="USD">'."\n" ;
echo '</form>'."\n" ;

/** This form will redraw the current page for approval. */
echo '<form action="ProductApprove.php" name="server_responder" method="post" target="_top">'."\n" ;
echo '<input type="hidden" name="trans" value="'.$transaction_start.'">'."\n" ;
echo '<input type="hidden" name="prod_id" value="'.$this->product_id.'">'."\n" ;
echo '</form>'."\n" ;

/** No form here just an input and a button.  onClick will handle all the forms */
echo '<input type="image" src="https://www.sandbox.bank.com/en_US/i/btn/btn_purchaseimmediateCC_LG.gif" border="0" alt="This Bank - The safer, easier way to pay!" onclick="serverNotifySelected()">'."\n" ;
echo '<img alt="" border="0" src="https://www.sandbox.bank.com/en_US/i/scr/pixel.gif" width="1" height="1">'."\n" ;

上面的代码用于页面上的一个按钮。发生的情况是:您按下按钮,当前页面从 [product to purchase] 更改为 [pre-approval] 并打开一个新页面,该页面获得焦点,并传递给支付提供商。

这样,当用户完成支付服务提供商,并且用户只是关闭支付服务提供商的窗口,并且不使用 [返回您的网站] 按钮时,您的网站已准备就绪并在预批准屏幕中等待!

于 2013-09-12T05:02:19.627 回答