we’ll walk you through how to integrate PayPal API with a microservice architecture to enable seamless payment processing on your eCommerce website. By leveraging PayPal’s powerful payment solutions and a microservice approach, you can build a scalable, efficient, and secure payment system for your online store
What is paypal?
PayPal is a payment platform with a website and a phone app that enables payments through online money transfers. PayPal customers create an account and connect it to a checking account, a credit card, or both.Once identification and payment method are confirmed, users can send or receive payments online or make purchases using PayPal as the go-between. Millions of small and large retailers accept PayPal payments online and in person
Architecture:
Paypal checkout API:
- source code
Use:"https://www.paypalobjects.com/api/checkout.js"
paypal.Button.render({
env: 'sandbox', // sandbox | production
client: {
sandbox: 'xxxxxxxxxx',
production: 'xxxxxxxxxx'
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function(data, actions) {
// Make a call to the REST API to set up the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total:document.getElementById("total-hidden-charges").value, currency: 'USD' }
}
],
redirect_urls: {
return_url: 'http://localhost:8090/index',
cancel_url: 'http://localhost:8090/order'
}
}
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
actions.payment.execute().then(function() {
fetch('http://localhost:8060/order/', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID,
data: mapToObj(Items),
user_id:Cookies.get("user_id")
})
});
alert("Booking successfully!");
return actions.redirect();
}
);
},
onCancel: function(data, actions) {
actions.redirect();
}
}, '#paypal-button-container');
- Redirect_urls: for us to set payment complete and cancel redirect url
- OnAuthorize: is called when the buyer approves the payment and I also send a request to my order service for updating product quantity
- OnCancel: is called when the buyer cancel
Result:
Reference:
Paypal
Paypal developer
PayPal-Java-SDK
PayPal 付款流程整合 後篇
django-shop-tutorial
How to set Domain name for different service in kubernetes