summaryrefslogtreecommitdiff
path: root/views/mods/mod_paypalapi/overview_button.phtml
diff options
context:
space:
mode:
authorDaniel Schmitzer <noreply@maennchen1.de>2024-08-13 14:15:58 +0000
committerDaniel Schmitzer <noreply@maennchen1.de>2024-08-13 14:15:58 +0000
commit48d0b28f70e0687b78399cfe7c1759a2000651e0 (patch)
treea0318aab1c8b3f59ed1ecfe4689731258d6a0e4a /views/mods/mod_paypalapi/overview_button.phtml
parent79a112f930034c276575e2751a226ccb0e6f1974 (diff)
git-svn-id: https://[internal]/wordpress/plugins/wpsg4@8420 0d5edaf7-2b12-4e95-93f4-047927463d4b
Diffstat (limited to 'views/mods/mod_paypalapi/overview_button.phtml')
-rw-r--r--views/mods/mod_paypalapi/overview_button.phtml89
1 files changed, 89 insertions, 0 deletions
diff --git a/views/mods/mod_paypalapi/overview_button.phtml b/views/mods/mod_paypalapi/overview_button.phtml
new file mode 100644
index 0000000..dfe5490
--- /dev/null
+++ b/views/mods/mod_paypalapi/overview_button.phtml
@@ -0,0 +1,89 @@
+<?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> \ No newline at end of file