0
私は正常に私のウェブサイトでの支払い方法としてAPIを介してペイパルを統合しました。ここでは、コードは以下のとおりです。 - フロントエンド:Paypalでのクレジット/デビットカードのお支払い方法
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');
バックエンド:
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
これは完全に働いています。しかし、私は顧客にクレジットカード/デビットカードでの支払いを可能にしたい。私の質問はフロントエンドとバックエンドからそれを有効にする方法ですか?