[IMP] payment_stripe: adjust the code for Stripe Connect
task-2982347 X-original-commit: fc890dc6e91a6731bf31a40ee77dad0f8697f5b4 Part-of: odoo/odoo#104387
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
'web.assets_frontend': [
|
||||
'payment_stripe/static/src/js/express_checkout_form.js',
|
||||
'payment_stripe/static/src/js/payment_form.js',
|
||||
'payment_stripe/static/src/js/stripe_options.js',
|
||||
],
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
|
||||
@@ -400,3 +400,20 @@ class PaymentProvider(models.Model):
|
||||
self.ensure_one()
|
||||
|
||||
return {}
|
||||
|
||||
#=== BUSINESS METHODS - GETTERS ===#
|
||||
|
||||
def _stripe_get_publishable_key(self):
|
||||
""" Return the publishable key of the provider.
|
||||
|
||||
This getter allows fetching the publishable key from a QWeb template and through Stripe's
|
||||
utils.
|
||||
|
||||
Note: `self.ensure_one()
|
||||
|
||||
:return: The publishable key.
|
||||
:rtype: str
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
return stripe_utils.get_publishable_key(self.sudo())
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { paymentExpressCheckoutForm } from '@payment/js/express_checkout_form';
|
||||
import { _prepareStripeOptions } from 'payment_stripe.payment_form';
|
||||
import { StripeOptions } from '@payment_stripe/js/stripe_options';
|
||||
|
||||
paymentExpressCheckoutForm.include({
|
||||
|
||||
@@ -55,7 +55,8 @@ paymentExpressCheckoutForm.include({
|
||||
}
|
||||
|
||||
const stripeJS = Stripe(
|
||||
providerData.stripePublishableKey, _prepareStripeOptions(providerData)
|
||||
providerData.stripePublishableKey,
|
||||
new StripeOptions()._prepareStripeOptions(providerData),
|
||||
);
|
||||
const paymentRequest = stripeJS.paymentRequest({
|
||||
country: providerData.countryCode,
|
||||
|
||||
@@ -1,49 +1,37 @@
|
||||
/** @odoo-module */
|
||||
/* global Stripe */
|
||||
odoo.define('payment_stripe.payment_form', require => {
|
||||
'use strict';
|
||||
|
||||
const checkoutForm = require('payment.checkout_form');
|
||||
const manageForm = require('payment.manage_form');
|
||||
import checkoutForm from 'payment.checkout_form';
|
||||
import manageForm from 'payment.manage_form';
|
||||
import { StripeOptions } from '@payment_stripe/js/stripe_options';
|
||||
|
||||
const stripeMixin = {
|
||||
const stripeMixin = {
|
||||
|
||||
/**
|
||||
* Redirect the customer to Stripe hosted payment page.
|
||||
*
|
||||
* @override method from payment.payment_form_mixin
|
||||
* @private
|
||||
* @param {string} code - The code of the payment option
|
||||
* @param {number} paymentOptionId - The id of the payment option handling the transaction
|
||||
* @param {object} processingValues - The processing values of the transaction
|
||||
* @return {undefined}
|
||||
*/
|
||||
_processRedirectPayment: function (code, paymentOptionId, processingValues) {
|
||||
if (code !== 'stripe') {
|
||||
return this._super(...arguments);
|
||||
}
|
||||
/**
|
||||
* Redirect the customer to Stripe hosted payment page.
|
||||
*
|
||||
* @override method from payment.payment_form_mixin
|
||||
* @private
|
||||
* @param {string} code - The code of the payment option
|
||||
* @param {number} paymentOptionId - The id of the payment option handling the transaction
|
||||
* @param {object} processingValues - The processing values of the transaction
|
||||
* @return {undefined}
|
||||
*/
|
||||
_processRedirectPayment: function (code, paymentOptionId, processingValues) {
|
||||
if (code !== 'stripe') {
|
||||
return this._super(...arguments);
|
||||
}
|
||||
|
||||
const stripeJS = Stripe(processingValues['publishable_key'],
|
||||
this._prepareStripeOptions(processingValues));
|
||||
stripeJS.redirectToCheckout({
|
||||
sessionId: processingValues['session_id']
|
||||
});
|
||||
},
|
||||
const stripeJS = Stripe(
|
||||
processingValues['publishable_key'],
|
||||
// Instantiate the StripeOptions class to allow patching the method and add options.
|
||||
new StripeOptions()._prepareStripeOptions(processingValues),
|
||||
);
|
||||
stripeJS.redirectToCheckout({
|
||||
sessionId: processingValues['session_id']
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepare the options to init the Stripe JS Object
|
||||
*
|
||||
* Function overriden in internal module
|
||||
*
|
||||
* @param {object} processingValues
|
||||
* @return {object}
|
||||
*/
|
||||
_prepareStripeOptions: function (processingValues) {
|
||||
return {};
|
||||
},
|
||||
};
|
||||
|
||||
checkoutForm.include(stripeMixin);
|
||||
manageForm.include(stripeMixin);
|
||||
|
||||
return stripeMixin;
|
||||
});
|
||||
checkoutForm.include(stripeMixin);
|
||||
manageForm.include(stripeMixin);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/** @odoo-module */
|
||||
|
||||
export class StripeOptions {
|
||||
/**
|
||||
* Prepare the options to init the Stripe JS Object.
|
||||
*
|
||||
* This method serves as a hook for modules that would fully implement Stripe Connect.
|
||||
*
|
||||
* @param {object} processingValues
|
||||
* @return {object}
|
||||
*/
|
||||
_prepareStripeOptions(processingValues) {
|
||||
return {};
|
||||
};
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
t-attf-id="o_stripe_express_checkout_container_{{provider_sudo.id}}"
|
||||
t-att-data-provider-id="provider_sudo.id"
|
||||
t-att-data-provider-code="provider_sudo.code"
|
||||
t-att-data-stripe-publishable-key="provider_sudo.stripe_publishable_key"
|
||||
t-att-data-stripe-publishable-key="provider_sudo._stripe_get_publishable_key()"
|
||||
t-att-data-country-code="provider_sudo.company_id.country_id.code"
|
||||
class="w-100 mt-2"/>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user