Subversion Repositories wpShopGermany4

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8420 daniel 1
<?php
2
 
3
	declare(strict_types=1);
4
 
5
	/**
6
	 * @author: daniel
7
	 * @date: 13.06.24
8
	 * @time: 14:48
9
	 */
10
 
11
	namespace wpsg;
12
 
13
?>
14
 
15
<?php GiroPayPalAPI::getInstance()->integrateSDK(); ?>
16
 
17
 
18
<div style="width:300px; float:right;">
19
	<div id="giropay-btn"></div>
20
</div>
21
 
22
<script>
23
 
24
	paypal.Buttons({
25
		fundingSource: paypal.FUNDING.GIROPAY,
26
		style: {
27
			label: "pay",
28
		},
29
		createOrder() {
30
 
31
			const form = document.getElementById('wpsg_form');
32
 
33
			if (form.checkValidity()) {
34
 
35
				return fetch("<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayCreateOrderFromSession', [ ], true); ?>", {
36
					method: "POST",
37
					headers: {
38
						"Content-Type": "application/json",
39
					},
40
					body: { }
41
				})
42
				.then((response) => response.json())
43
				.then((order) => order.id);
44
 
45
			} else form.reportValidity();
46
 
47
		},
48
		onApprove(data) {
49
 
50
			return fetch("<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayApproveOrder', [], true); ?>", {
51
				method: "POST",
52
				headers: {
53
					"Content-Type": "application/json",
54
				},
55
				body: JSON.stringify({
56
					orderID: data.orderID
57
				})
58
			})
59
				.then((response) => response.json())
60
				.then((orderData) => {
61
 
62
					location.href = orderData.order_done_url;
63
 
64
					// Successful capture! For dev/demo purposes:
65
					// console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
66
 
67
					// const transaction = orderData.order_paypal.purchase_units[0].payments.captures[0];
68
 
69
					//console.log('Transaction Status:',	transaction.status);
70
					//console.log('Transaction ID:', transaction.id);
71
 
72
			});
73
 
74
		},
75
		onCancel(data, actions) {
76
 
77
			console.log(`Order Canceled - ID: ${data.orderID}`);
78
 
79
			location.href = '<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayCancelOrder', [], true); ?>';
80
 
81
		},
82
		onError(err) {
83
 
84
			<?php if ($GLOBALS['wpsg_sc']->get_option('wpsg_debugModus') === "1") { ?>console.error(err);<?php } ?>
85
 
86
		}
87
	}).render("#giropay-btn");
88
 
89
</script>