summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikunj Ladava <nla@odoo.com>2021-03-25 10:24:10 +0000
committerNikunj Ladava <nla@odoo.com>2021-03-26 15:27:30 +0000
commitcf9d17eb344215a4872463d1942ab4111028fe21 (patch)
treef9079f0d2c81993024523943bcaa3fd037c805ee
parentab7ba0dd6ea7bce8e0372432321051862a246fad (diff)
[FIX] payment_stripe: fix transaction authentication
Before this commit: - stripe is configured to make payment with s2s - when any customer tries to make payment with stripe it will ask customer to authorize the transaction twice. it was intended from the setup intent, it will create a payment method from the intent and then we can make transactions for it. - here payment method is authorized by the user (the card that added by user to make payment) but while making the payment it requires the authorization again. After this commit: - it will directly create the payment method for the card if the customer tries to make payment and validate the transaction only hence, it won't have any issue like having an authorization form without showing any amount in it. - for adding the card from my/payment_methods flow will be the same as before closes odoo/odoo#68413 Opw: 2476493 X-original-commit: 63a29cd463f85a820dc0ddac50baa36ffd42c349 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
-rw-r--r--addons/payment_stripe/static/src/js/payment_form.js38
1 files changed, 30 insertions, 8 deletions
diff --git a/addons/payment_stripe/static/src/js/payment_form.js b/addons/payment_stripe/static/src/js/payment_form.js
index 311f62bfc8e..4a11e289e85 100644
--- a/addons/payment_stripe/static/src/js/payment_form.js
+++ b/addons/payment_stripe/static/src/js/payment_form.js
@@ -23,6 +23,32 @@ PaymentForm.include({
// Private
//--------------------------------------------------------------------------
+ /**
+ * called to create payment method object for credit card/debit card.
+ *
+ * @private
+ * @param {Object} stripe
+ * @param {Object} formData
+ * @param {Object} card
+ * @param {Boolean} addPmEvent
+ * @returns {Promise}
+ */
+ _createPaymentMethod: function (stripe, formData, card, addPmEvent) {
+ if (addPmEvent) {
+ return this._rpc({
+ route: '/payment/stripe/s2s/create_setup_intent',
+ params: {'acquirer_id': formData.acquirer_id}
+ }).then(function(intent_secret) {
+ return stripe.handleCardSetup(intent_secret, card);
+ });
+ } else {
+ return stripe.createPaymentMethod({
+ type: 'card',
+ card: card,
+ });
+ }
+ },
+
/**
* called when clicking on pay now or add payment event to create token for credit card/debit card.
*
@@ -52,20 +78,16 @@ PaymentForm.include({
if (card._invalid) {
return;
}
- return this._rpc({
- route: '/payment/stripe/s2s/create_setup_intent',
- params: {'acquirer_id': formData.acquirer_id}
- }).then(function(intent_secret){
- return stripe.handleCardSetup(intent_secret, card);
- }).then(function(result) {
+ this._createPaymentMethod(stripe, formData, card, addPmEvent).then(function(result) {
if (result.error) {
return Promise.reject({"message": {"data": { "arguments": [result.error.message]}}});
} else {
- _.extend(formData, {"payment_method": result.setupIntent.payment_method});
+ const paymentMethod = addPmEvent ? result.setupIntent.payment_method : result.paymentMethod.id;
+ _.extend(formData, {"payment_method": paymentMethod});
return self._rpc({
route: formData.data_set,
params: formData,
- })
+ });
}
}).then(function(result) {
if (addPmEvent) {