【发布时间】:2019-07-29 15:45:44
【问题描述】:
我应该如何使用 paypal SDK 将 orderID 发布到服务器?示例代码在 localhost 和远程主机上都不起作用。我提交 PayPal 按钮后,帖子为空。
据此, https://developer.paypal.com/docs/checkout/integrate/#6-verify-the-transaction
PayBundle\Resources\actions\ppal\ppalAction_brt_stkovr.php
<?php
use PayBundle\actions\Order;
echo "<br><br> POST ="; print_r($_POST);
file_put_contents( PHP_EOL . PHP_EOL . __DIR__ .'/out.php', json_encode( $_POST ) .' from '.__FILE__, FILE_APPEND );
include_once ( PATH_ACTIONS_PAY . '/ppal/__init.php' );
include_once ( PATH_ACTIONS_PAY . '/ppal/__payAInit.php' );
require_once PATH_VENDOR . '/braintree/braintree_php/lib/Braintree.php';
use Sample\PayPalClient;
use PayPalCheckoutSdk\Orders\OrdersGetRequest;
Braintree_Configuration::environment( 'sandbox' );
Braintree_Configuration::merchantId( 'x' );
Braintree_Configuration::publicKey( 'y' );
Braintree_Configuration::privateKey( 'z' );
if( isset($_POST['payPp'] ) ) {
include_once ( PATH_ACTIONS_PAY . '/ppal/pay/'.$this->vdArr['lang'].'/__Bk.php' );
echo "<br> from ppalAction orderID = "; print_r($this->vdArr['orderID']);
if ( !count(debug_backtrace()) ) {
$ppalOrder = new GetOrder();
$ppalOrder->getOrder( $this->vdArr['orderID'], true);
} // if ( !count(debug_backtrace())
} // if( isset($_POST['paypalA'] ) ) {
else {
$this->vdArr['tokenPpal'] = Braintree_ClientToken::generate();
}
客户端代码:
<script type='text/javascript' >
window.onload = function() {
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function( data, actions ) {
return actions.order.capture().then( function(details) {
//alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
//console.log('Transaction completed' ); alert(details);
console.log( 'data.orderID = ' + data.orderID );
document.getElementById('orderID').value = data.orderID;
console.log('data'); console.log(data);
console.log('Transaction completed by ' + details.payer.name.given_name );
//return fetch('/paypal-transaction-complete', {
return fetch( 'https://typejoy.biz/pay/ppal_1025/EN/pay', {
method: 'POST',
body: JSON.stringify({
orderID: data.orderID,
payPp: 1
})
}); // return fetch( 'https://typejoy.biz/pay/ppal_1025/EN/pay
}); // return actions.order.capture().then( function(details
} // onApprove: function(data, actions
}).render('#payPp');
} // window.onload = function() {
</script>
在 clinet 端控制台中,我可以记录 orderID,但我不明白如何将其传递到服务器端。获取功能如何工作?我应该使用其他类型的功能吗?如何以正确的方式做到这一点?
【问题讨论】:
标签: javascript php paypal