Reputation: 81
I want to integrate Paypal Checkout on my website build with Polymer. To do so I try to use Paypal Smart Payment Buttons which is supposed to be the simplest way to integrate Paypal. But it seems that the Paypal Checkout library is not really compliant with Polymer and Shadow-DOM.
iframe
that pointing to a HTML file which render the buttons correctly. When I click on the button I am correctly redirected to the Paypal Checkout page but a blocking error occurs inside the Paypal page and I can not finalize the payment.I also tried to integrated the Paypal Checkout avoiding the Paypal library but I did not find any consistent documentation to do so.
first try (in Shadow-DOM):
<div id="button"></div>
...
initPayment () {
paypal.Buttons({
createOrder: function(data, actions) {
console.log(data, actions);
let order = actions.order.create({
purchase_units: [{
amount: {
value: "0.01",
currency_code: "EUR"
},
reference_id: "123"
}]
});
return order;
},
onApprove: function(data, actions) {
return actions.order.capture().then((detail) => {
console.log(detail);
});
},
onError: function(error) {
console.log(error);
},
onCancel: (data, actions) => {
console.log(data);
},
}).render(this.shadowRoot.querySelector("#button"));
...
iframe
):...
<body>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
console.log(data, actions);
let order = actions.order.create({
purchase_units: [{
amount: {
value: "0.01",
currency_code: "EUR"
},
reference_id: "123"
}]
});
return order;
},
onApprove: function(data, actions) {
return actions.order.capture().then((detail) => {
console.log(detail);
});
},
onError: function(error) {
console.log(error);
},
onCancel: (data, actions) => {
console.log(data);
},
}).render("#button");
</script>
...
<div id="button"></div>
</body>
Also I observed that when I test my HTML page apart which is supposed to be include with an iframe
the checkout works fine.
Upvotes: 0
Views: 337
Reputation: 11
You can work around this limitation in PayPal by adding an additional step to the checkout.
On our site we show selection of "Paypal, Apple Pay, Google Pay, CC". When the user selects Paypal we add the following elements to the body (not in shadow dom)...
<div style="display: flex; width:100vw; height: 100vh;opacity:.8;background:#000">
<div id="paypal-button" style="display:flex;flex-grow:1;align-self:center;justify-content:center"></div>
</div>
After that call window.paypal.Button.render with
style: { size: 'responsive', layout: 'vertical' }
This will put the PayPal button, PayPal credit button and PayPal CC buttons centered on the screen.
Then in the render onCancel/onError/onAuthorize tear down the backdrop and the paypal buttons.
Upvotes: 1