Subversion Repositories wpShopGermany4

Rev

Blame | Last modification | View Log | RSS feed

<?php

    /**
     *
     */

?>

<script async="async" src="https://static-eu.payments-amazon.com/OffAmazonPayments/de/sandbox/lpa/js/Widgets.js"></script>

<div id="AmazonLoginButton_wrap">
    <div id="AmazonLoginButton"></div>
</div>

<div id="addressBookWidgetDiv"></div>
<div id="walletWidgetDiv"></div>

<input type="text" name="amazon[OrderReference]" id="wpsg_mod_amazon_OrderReference" value="" />

<script>

    window.onAmazonLoginReady = function() {

        amazon.Login.setClientId('<?php echo $this->get_option('wpsg_mod_amazon_v2_store_id'); ?>');

    };

    window.onAmazonPaymentsReady = function() {

        var authRequest;

        OffAmazonPayments.Button('AmazonLoginButton', '<?php echo $this->get_option('wpsg_mod_amazon_v2_seller_id'); ?>', {

            type:  'PwA',
            color: 'Gold',
            size:  'small',
            language: 'de-DE',

            authorization: function() {

                loginOptions = {
                    scope: "profile payments:widget payments:shipping_address payments:billing_address",
                    popup: true
                };

                authRequest = amazon.Login.authorize (loginOptions, '<?php echo $this->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon_v2', 'login', [], true) ?>');

            }
        });

        <?php if (isset($_SESSION['wpsg_mod_amazon_v2_access_token'])) { ?>

            new OffAmazonPayments.Widgets.AddressBook({
                sellerId: '<?php echo $this->get_option('wpsg_mod_amazon_v2_seller_id'); ?>',
                scope: 'profile payments:widget payments:shipping_address payments:billing_address',
                onOrderReferenceCreate: function(orderReference) {

                    var oID = orderReference.getAmazonOrderReferenceId();

                    jQuery('#wpsg_mod_amazon_OrderReference').val(oID);

                },
                onAddressSelect: function(orderReference) {
                    // Replace the following code with the action that you want
                    // to perform after the address is selected. The
                    // amazonOrderReferenceId can be used to retrieve the address
                    // details by calling the GetOrderReferenceDetails operation.
                },
                design: {
                    designMode: 'responsive'
                },
                onReady: function(orderReference) {
                    // Enter code here you want to be executed
                    // when the AddressBook widget has been rendered.
                },

                onError: function(error) {

                    console.log(error);

                    // Your error handling code.
                    // During development you can use the following
                    // code to view error messages:
                    // console.log(error.getErrorCode() + ': ' + error.getErrorMessage());
                    // See "Handling Errors" for more information.
                }
            }).bind("addressBookWidgetDiv");

            new OffAmazonPayments.Widgets.Wallet({
                sellerId: '<?php echo $this->get_option('wpsg_mod_amazon_v2_seller_id'); ?>',
                onPaymentSelect: function(orderReference) {

                    // Replace this code with the action that you want to perform
                    // after the payment method is selected.

                },
                design: {
                    designMode: 'responsive'
                },
                onError: function(error) {
                    alert("Wallet: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
                }
            }).bind("walletWidgetDiv");

        <?php } ?>

    }

</script>

<style>

    #addressBookWidgetDiv {
        min-width: 300px;
        width: 100%;
        max-width: 900px;
        min-height: 228px;
        height: 240px;
        max-height: 400px;
        margin-bottom:2rem;
    }

    #walletWidgetDiv {
        min-width: 300px;
        width: 100%;
        max-width: 900px;
        min-height: 228px;
        height: 240px;
        max-height: 400px;
        margin-bottom:2rem;
    }

</style>