Skip to content

Instantly share code, notes, and snippets.

@matthewarkin
Created February 9, 2016 21:39
Show Gist options
  • Save matthewarkin/8f27ac2b4998e90ca383 to your computer and use it in GitHub Desktop.
Save matthewarkin/8f27ac2b4998e90ca383 to your computer and use it in GitHub Desktop.
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<form id="form" action="chargeCustomer.php" method="POST">
</form>
<div id="paypal-container"></div>
<script type="text/javascript">
braintree.setup("<?php echo($gateway->clientToken()->generate());?>", "custom", {
paypal: {
container: "paypal-container",
singleUse: true, // Required
amount: 10.00, // Required
currency: 'USD', // Required
locale: 'en_us',
enableShippingAddress: 'true',
shippingAddressOverride: {
recipientName: 'Scruff McGruff',
streetAddress: '1234 Main St.',
extendedAddress: 'Unit 1',
locality: 'Chicago',
countryCodeAlpha2: 'US',
postalCode: '60652',
region: 'IL',
phone: '123.456.7890',
editable: false
}
},
onPaymentMethodReceived: function (obj) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = '$_POST['payment_method_nonce']';
input.value = obj.nonce;
document.getElementById('form').appendChild(input);
document.getElementById('form').submit()
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment