问题
I am working with braintree paypal checkout, it is working fine for me, but i am not able to add tax and shipping charge, i tried to get some information, but that is also not working for me, here is my current code for braintree checkout
var form = document.querySelector('#payment-form');
var client_token = "<?php echo \Braintree\ClientToken::generate(); ?>";
// Render the PayPal button
paypal.Button.render({
// Pass in the Braintree SDK
braintree: braintree,
// Pass in your Braintree authorization key
client: {
sandbox: client_token,
production: '<insert production auth key>'
},
// Set your environment
env: 'sandbox', // sandbox | production
// Wait for the PayPal button to be clicked
payment: function(data, actions) {
// Make a call to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: <?php echo $cart_total_amount; ?>,
currency: 'USD'
}
}
]
}
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
// Call your server with data.nonce to finalize the payment
console.log('Braintree nonce:', data.nonce);
// Get the payment and buyer details
return actions.payment.get().then(function(payment) {
$("div#divLoading").addClass('show');
console.log('Payment details:', payment);
var payment_id = payment.id;
var total_amount = '<?php echo $cart_total_amount; ?>';
$.ajax({
type: 'POST',
url : '<?php $_SERVER["DOCUMET_ROOT"] ?>/media/secure_checkout/create_order_braintree.php',
data : 'payment_id='+payment_id+'&total_amount='+total_amount,
dataType : 'json',
success: function(msg) {
$("div#divLoading").removeClass('show');
if(msg.status == '1') {
//$("#myModal").modal('show');
document.location.href= 'http://<?php echo $_SERVER['HTTP_HOST']; ?>/media/secure_checkout/checkout.php?payment=confirm';
}
},
error: function(msg) {
$("div#divLoading").removeClass('show');
}
});
});
}
}, '#paypal-button-container');
Can anyone please tell me what i need to do to add tax and shipping charge in it?
回答1:
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support@braintreepayments.com.
Braintree doesn't have parameters for tax
or shipping
. You'll need to create this logic on your side and pass the total into the amount
parameter.
回答2:
It seems like you're following the code at Integrate PayPal Checkout Using the Braintree SDK. Check out the available options for the actions.payment.create()
call here. Note that tax
and shipping
are there. More details on the Payments API page. Note: You still need to calculate the total so it includes tax and shipping, like Erica said.
If you want to create the payments server-side, it seems you can pass taxAmount and shippingAmount to Braintree's transaction::sale() method. It's also possible to pass these at a line-item level. Again, you need to calculate the total so it includes tax and shipping. It seems you'll have to include some other fields as well, since taxAmount
is a Level 2 field, and shippingAmount
is a Level 3 field. I haven't used it, so I can't say how it works, or how well it works. I imagine (hope) these fields get passed onto PayPal, if PayPal is used as payment method.
For recurring transactions: I don't see any tax/shipping-specific fields, but you can override the price
to include tax when you create the subscription (at least with the server-side Braintree API). Alternatively, I think if you create an add-on for tax, you could override that at subscription-create time without knowing the subscription price. Either way, I'm not sure if you can easily update the subscription as tax rates change (as laws change).
来源:https://stackoverflow.com/questions/46489672/how-can-we-add-tax-and-shipping-charge-in-braintree-paypal-checkout