Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialises BNPL payment messaging element with Stripe account ID #8377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-adds-correct-options-to-bnpl-messaging-element
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Uses WCPayAPI to initialise Stripe for BNPL payment element, includes necessary required parameters.
16 changes: 13 additions & 3 deletions client/product-details/bnpl-site-messaging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@
* Internal dependencies
*/
import './style.scss';
import WCPayAPI from 'wcpay/checkout/api';

export const initializeBnplSiteMessaging = () => {
const {
productVariations,
country,
locale,
accountId,
publishableKey,
paymentMethods,
} = window.wcpayStripeSiteMessaging;

// eslint-disable-next-line no-undef
const stripe = Stripe( publishableKey );
const api = new WCPayAPI(
{
publishableKey: publishableKey,
accountId: accountId,
locale: locale,
},
null
);
const options = {
amount: parseInt( productVariations.base_product.amount, 10 ) || 0,
currency: productVariations.base_product.currency || 'USD',
paymentMethodTypes: paymentMethods || [],
countryCode: country, // Customer's country or base country of the store.
};
const paymentMessageElement = stripe
const paymentMessageElement = api
.getStripe()
.elements()
.create( 'paymentMethodMessaging', options );
paymentMessageElement.mount( '#payment-method-message' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function init(): string {
'productId' => 'base_product',
'productVariations' => $product_variations,
'country' => empty( $billing_country ) ? $store_country : $billing_country,
'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ),
'accountId' => $this->account->get_stripe_account_id(),
'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ),
'paymentMethods' => array_values( $bnpl_payment_methods ),
]
Expand Down
Loading