Subversion Repositories wpShopGermany4

Rev

Blame | Last modification | View Log | RSS feed

<?php
        
        declare(strict_types=1);
        
        /**
         * @author: daniel
         * @date: 13.06.24
         * @time: 14:59
         */
        
        namespace wpsg;
        
        $client_id = $this->view['clientId']??null;

?>

<?php if ($client_id !== null) { ?>
        
        <p><?php echo __('Die Bestellung ist bei uns eingegangen, bitte begleichen Sie den offenen Betrag mit giroPAy über folgenden Button.', 'wpsg'); ?></p>
        
        <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>
        
        <div id="giropay-btn"></div>
        
        <script>
                
                paypal.Buttons({
                        fundingSource: paypal.FUNDING.GIROPAY,
                        style: {
                                label: "pay",
                        },
                        createOrder() {
                                return fetch('<?php echo $this->getUrl(\wpsg_ShopController::URL_BASKET, 'wpsg_mod_paypalapi', 'giroPayCreateOrder', [
                                        'order_id' => intval($_REQUEST['order_id'])
                                ], true); ?>', {
                                        method: "POST",
                                        headers: {
                                                "Content-Type": "application/json",
                                        },
                                        body: null,
                                })
                                .then((response) => response.json())
                                .then((order) => order.id);
                        },
                        onApprove(data) {

                                console.log('onApprove');
                                
                                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) => {
                                        
                                        //console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
                                        //const transaction = orderData.purchase_units[0].payments.captures[0];
                                        //console.log('Transaction Status:',    transaction.status);
                                        //console.log('Transaction ID:', transaction.id);
                                        
                                        location.reload();
                                        
                                });
                        },
                        onCancel(data, actions) { console.log(`Order Canceled - ID: ${data.orderID}`); },
                        onError(err) { console.error(err); }
                }).render("#giropay-btn");
                
        </script>
        
<?php } else { ?>

        <p><?php echo __('Den Betrag haben wir mittels GiroPay dankend erhalten.', 'wpsg'); ?></p>

<?php }