Last active
December 24, 2019 05:17
-
-
Save komuw/0bf5fd3229a98336f215f4622e1838cc to your computer and use it in GitHub Desktop.
create paypal express checkout app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a paypal express checkout app | |
1. create a sandbox paypal app: https://developer.paypal.com/developer/applications (under REST API apps) | |
2. copy the app email([email protected]), client_id(Ac3vNqODzxe40U2kczQd92e4CGDor1SVM7GBfHzimCflhTaS6CtHW-jHMwys1RAKFzfLM-vX7xFPfCzo | |
) | |
3. use the client_id from above and replace it in the html_snippet below | |
4. configure webhooks for any events that occur: https://developer.paypal.com/docs/integration/direct/webhooks/rest-webhooks/ | |
example of events that can occur-> https://developer.paypal.com/docs/integration/direct/webhooks/event-names/ | |
5. setup a Return URL - Target URL where users will be redirected after test transactions. Please allow up to 3 hours for the change to go into effect. | |
6. You will go through the same steps later on when you want to create the proper LIVE prod paypal. app | |
//my_page.html | |
<body> | |
<div id="paypal-button"></div> | |
<script src="https://www.paypalobjects.com/api/checkout.js"></script> | |
<script> | |
paypal.Button.render({ | |
env: 'sandbox', // Optional: specify 'sandbox' environment | |
client: { | |
// this here is the client_id and NOT client_secret | |
// so list the client id's for your different environments | |
sandbox: 'client_id_from_process_above', | |
production: 'client_id_for_prod_live' | |
}, | |
payment: function() { | |
var env = this.props.env; | |
var client = this.props.client; | |
return paypal.rest.payment.create(env, client, { | |
transactions: [ | |
{ | |
amount: { total: '1.00', currency: 'USD' } | |
} | |
] | |
}); | |
}, | |
commit: true, // Optional: show a 'Pay Now' button in the checkout flow | |
onAuthorize: function(data, actions) { | |
// Optional: display a confirmation page here | |
return actions.payment.execute().then(function() { | |
// Show a success page to the buyer | |
}); | |
} | |
}, '#paypal-button'); | |
</script> | |
</body> | |
see: https://github.com/paypal/paypal-checkout/blob/6f5202ab70860dd2956506c87b8d9a989b9447dd/src/api/rest.js#L15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment