Skip to content

Instantly share code, notes, and snippets.

@schube
Created August 8, 2019 08:39
Show Gist options
  • Select an option

  • Save schube/84811d3a6520bbec5563673730c2440f to your computer and use it in GitHub Desktop.

Select an option

Save schube/84811d3a6520bbec5563673730c2440f to your computer and use it in GitHub Desktop.
Paypal Buttons SDK with Customer Data
<!DOCTYPE html>
<head>
<!-- Add meta tags for mobile and IE -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=sb&currency=USD"></script>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
application_context: {
shipping_preference: "NO_SHIPPING"
},
payer: {
email_address: '[email protected]',
name: {
given_name: 'Hansi',
surname: 'Schmidt'
},
address: {
address_line_1: "Musterstrasse 18",
address_line_2: "Test",
admin_area_1: "",
admin_area_2: "Wien",
postal_code: "1010",
country_code: "DE"
}
},
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment