Blame | Last modification | View Log | RSS feed
<?php
declare(strict_types=1);
/**
* @author: daniel
* @date: 13.06.24
* @time: 14:48
*/
namespace wpsg;
?>
<?php GiroPayPalAPI::getInstance()->integrateSDK(); ?>
<div style="width:300px; float:right;">
<div id="giropay-btn"></div>
</div>
<script>
paypal.Buttons({
fundingSource: paypal.FUNDING.GIROPAY,
style: {
label: "pay",
},
createOrder() {
const form = document.getElementById('wpsg_form');
if (form.checkValidity()) {
return fetch("<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayCreateOrderFromSession', [ ], true); ?>", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: { }
})
.then((response) => response.json())
.then((order) => order.id);
} else form.reportValidity();
},
onApprove(data) {
return fetch("<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayApproveOrder', [], true); ?>", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
orderID: data.orderID
})
})
.then((response) => response.json())
.then((orderData) => {
location.href = orderData.order_done_url;
// Successful capture! For dev/demo purposes:
// console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
// const transaction = orderData.order_paypal.purchase_units[0].payments.captures[0];
//console.log('Transaction Status:', transaction.status);
//console.log('Transaction ID:', transaction.id);
});
},
onCancel(data, actions) {
console.log(`Order Canceled - ID: ${data.orderID}`);
location.href = '<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayCancelOrder', [], true); ?>';
},
onError(err) {
<?php if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugModus') === "1") { ?>console.error(err);<?php } ?>
}
}).render("#giropay-btn");
</script>