G
G
gitdev2017-11-09 12:53:40
API
gitdev, 2017-11-09 12:53:40

Paypal subscribe button, how to track the payment?

Is it possible to create a paypal subscription button so that it opens in an iframe or at least with the ability to track that the user has made a payment.
I created a regular payment button using js (an example of a button is below). You need a paypal subscribe button, ideally so that it also opens programmatically through an iframe, but an option with the ability to track this event through pre-addressing is suitable.

//var sum = parseFloat($('#payment_total_sum').text()).toFixed(2);
    paypal.Button.render({
        env: 'sandbox', // sandbox | production
        // PayPal Client IDs - replace with your own
        // Create a PayPal app: https://developer.paypal.com/developer/applications/create
        client: {
            sandbox: 'cawcaw-wcaw',
            production: 'Access to site'
        },
        // Show the buyer a 'Pay Now' button in the checkout flow
        commit: true,
        // payment() is called when the button is clicked
        payment: function (data, actions) {
            // Make a call to the REST api to create the payment
            return actions.payment.create({
                payment: {
                    transactions: [
                        {
                            amount: {total: '0.01', currency: 'USD'}
                        }
                    ]
                }
            });
        },
        // onAuthorize() is called when the buyer approves the payment
        onAuthorize: function (data, actions) {
            // Make a call to the REST api to execute the payment
            return actions.payment.execute().then(function () {
                $.ajax({
                    method: "POST",
                    url: $('.do_pay_form').attr('action'),
                    //data: $('.payment_form').serialize(),
                    //data: $('.payment_form').serialize() + $(this).serialize(),
                    data: $('.do_pay_form, .payment_form').serialize(),
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 200) {
                            $('.do_pay_form')[0].reset();
                            $('.payment_form')[0].reset();
                            $('.paid-model').modal('show');
                        } else {
                            $('#' + data.error.key).addClass('input_container_error');
                        }
                    },
                    beforeSend: function () {
                    }
                });
            });
        }
    }, '#paypal-button-container');

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question