Subversion Repositories wpShopGermany4

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7787 daniel 1
<?php
2
 
3
    /**
4
     *
5
     */
6
 
7
?>
8
 
9
<script async="async" src="https://static-eu.payments-amazon.com/OffAmazonPayments/de/sandbox/lpa/js/Widgets.js"></script>
10
 
11
<div id="buy-now">JETZT kaufen</div>
12
 
13
<script>
14
 
15
    var sellerId = '<?php echo $this->get_option('wpsg_mod_amazon_v2_seller_id'); ?>';
16
    var id = '<?php echo $_SESSION['wpsg_mod_amazon_v2_amazonCheckoutSessionId']; ?>';
17
    var buyNowBtn = document.getElementById("buy-now");
18
 
19
    buyNowBtn.addEventListener('click', function () {
20
 
21
        OffAmazonPayments.initConfirmationFlow(sellerId, id, function(confirmationFlow) {
22
 
23
            placeOrder(confirmationFlow);
24
 
25
        });
26
 
27
    });
28
 
29
    function placeOrder(confirmationFlow) {
30
 
31
        jQuery.ajax({
32
            url: '<?php echo $this->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon_v2', 'placeOrder', [], true) ?>',
33
success: function (data) {
34
confirmationFlow.success(); // continue Amazon Pay hosted site
35
},
36
error: function (data) { // called on ajax error and timeout
37
confirmationFlow.error(); // abort Amazon Pay initConfirmationFlow
38
// you might want to add additional error handling
39
},
40
timeout: "your timeout value" //specify your timeout value (for example, 3000)
41
//If the ajax request takes longer than this timeout (in ms), the error callback
42
//will be called
43
});
44
 
45
    }
46
 
47
</script>