Sha256: 7e7b74e508305b939f31eeaa506ed35855af5705e5d6d7ed53accdab3bf1f687

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

/**
 * @namespace WORKAREA.paypalButtons
 */
WORKAREA.registerModule('paypalButtons', (function () {
    'use strict';

    var requestWrapper = function (requestData) {
            var deferred = $.Deferred();

            $.ajax(requestData)
            .done(function(data) {
                deferred.resolve(data);
            })
            .fail(function(data, status, xhr) {
                deferred.reject(xhr);
            });

            return deferred.promise();
        },

        createOrder = function() {
            return requestWrapper({
                url: WORKAREA.routes.storefront.paypalPath(),
                type: 'post',
                dataType: 'json'
            }).then(function (data) {
                return data.id;
            });
        },

        onApprove = function(data) {
            return requestWrapper({
                url: WORKAREA.routes.storefront.paypalApprovedPath({ id: data.orderID }),
                type: 'put',
                dataType: 'json'
            }).then(function(data) {
                window.location = data.redirect_url; }
            );
        },

        getConfig = function () {
            return _.assign({}, WORKAREA.config.paypalButtons, {
                createOrder: createOrder,
                onApprove: onApprove
            });
        },

        setup = function($container) {
            paypal
            .Buttons(getConfig())
            .render($container[0]);
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.paypalButtons
         */
        init = function ($scope) {
            var $buttonContainer = $('#paypal-button-container', $scope);

            if (window.paypal === undefined) { return; }
            if (_.isEmpty($buttonContainer)) { return; }

            setup($buttonContainer);
        };

    return {
        init: init
    };
}()));

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-paypal-3.0.4 app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js
workarea-paypal-3.0.3 app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js
workarea-paypal-3.0.2 app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js
workarea-paypal-3.0.1 app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js
workarea-paypal-3.0.0 app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js