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:59
9
	 */
10
 
11
	namespace wpsg;
12
 
13
	$client_id = $this->view['clientId']??null;
14
 
15
?>
16
 
17
<?php if ($client_id !== null) { ?>
18
 
19
	<p><?php echo __('Die Bestellung ist bei uns eingegangen, bitte begleichen Sie den offenen Betrag mit giroPAy über folgenden Button.', 'wpsg'); ?></p>
20
 
21
	<script src="https://sandbox.paypal.com/sdk/js?client-id=<?php echo $client_id; ?>&components=buttons,payment-fields,marks,funding-eligibility&enable-funding=giropay&currency=EUR"></script>
22
 
23
	<div id="giropay-btn"></div>
24
 
25
	<script>
26
 
27
		paypal.Buttons({
28
			fundingSource: paypal.FUNDING.GIROPAY,
29
			style: {
30
				label: "pay",
31
			},
32
			createOrder() {
33
				return fetch('<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayCreateOrder', [
34
					'order_id' => intval($_REQUEST['order_id'])
35
				], true); ?>', {
36
					method: "POST",
37
					headers: {
38
						"Content-Type": "application/json",
39
					},
40
					body: null,
41
				})
42
				.then((response) => response.json())
43
				.then((order) => order.id);
44
			},
45
			onApprove(data) {
46
 
47
				console.log('onApprove');
48
 
49
				return fetch('<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayApproveOrder', [], true); ?>', {
50
					method: "POST",
51
					headers: {
52
						"Content-Type": "application/json",
53
					},
54
					body: JSON.stringify({
55
						orderID: data.orderID
56
					})
57
				})
58
				.then((response) => response.json())
59
				.then((orderData) => {
60
 
61
					//console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
62
					//const transaction = orderData.purchase_units[0].payments.captures[0];
63
					//console.log('Transaction Status:',	transaction.status);
64
					//console.log('Transaction ID:', transaction.id);
65
 
66
					location.reload();
67
 
68
				});
69
			},
70
			onCancel(data, actions) { console.log(`Order Canceled - ID: ${data.orderID}`); },
71
			onError(err) { console.error(err); }
72
		}).render("#giropay-btn");
73
 
74
	</script>
75
 
76
<?php } else { ?>
77
 
78
	<p><?php echo __('Den Betrag haben wir mittels GiroPay dankend erhalten.', 'wpsg'); ?></p>
79
 
80
<?php }