mercredi 23 août 2017

How to pay with credit / debit card in paypal checkout?

I successfully integrated Paypal as payment method in my website through APIs. Here is the code:- frontend:

paypal.Button.render({
        env: self.get('paypalEnv'), // 'production' Or 'sandbox'
        commit: true, // Show a 'Pay Now' button
        payment: function() {
            return paypal.request.post(self.get('creationUrl')).then(function(data) {
                return data.id;
            });
        },
        onAuthorize: function(data) {
            return paypal.request.post(self.get('executionUrl'), {
                paymentID: data.paymentID,
                payerID: data.payerID
            }).then(function() {
                // The payment is complete!
                // You can now show a confirmation message to the customer
            });
        }
    }, '#paypal-button3');

backend:

module PortalPaypalPaymentService
    def self.create_payment(request)
        #debugger
        price_in_egp = request.initial_price
        output = CurrencyExchange.convert(price_in_egp*100, 'EGP', 'USD')
        price_in_usd = (output.cents/100.0).round(2)
        params = {
            "intent": "sale",
            "redirect_urls": {
                "return_url": APP_CONFIG['paypal_return_url'],
                "cancel_url": APP_CONFIG['paypal_cancel_url']
            },
            "payer": {
                "payment_method": "paypal"
            },
            "transactions": [{
                "amount": {
                "total": price_in_usd,
                "currency": "USD"
                }
            }]
        }
        response = send_request_post(PAYMENT_URL, params)
        JSON.parse(response.body)["id"]
    end

    def self.execute_payment(payment_id, payer_id)
        params = {
            payer_id: payer_id
        }
        response = send_request_post(PAYMENT_URL + '/' + payment_id + '/execute', params)
        JSON.parse(response.body)
    end
end

This is working perfectly. However, I want to enable customer to pay via credit / debit cards. My question is How to enable that from frontend and backend?

Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire