enqueue and respect merchant option for disabling stripe express pay (https://github.com/woocommerce/woocommerce-blocks/pull/2920)
* enqueue and respect merchant option for disabling stripe express pay * don't even register express payment method if merchant has disabled it * add StripeServerData.allowPaymentRequest to typedef
This commit is contained in:
parent
de65c2ff8e
commit
e2b82561bd
|
@ -11,8 +11,15 @@ import {
|
|||
*/
|
||||
import stripeCcPaymentMethod from './credit-card';
|
||||
import PaymentRequestPaymentMethod from './payment-request';
|
||||
import { getStripeServerData } from './stripe-utils';
|
||||
|
||||
// Register Stripe Credit Card.
|
||||
registerPaymentMethod( ( Config ) => new Config( stripeCcPaymentMethod ) );
|
||||
registerExpressPaymentMethod(
|
||||
( Config ) => new Config( PaymentRequestPaymentMethod )
|
||||
);
|
||||
|
||||
// Register Stripe Payment Request (Apple/Chrome Pay) if enabled.
|
||||
if ( getStripeServerData().allowPaymentRequest ) {
|
||||
registerExpressPaymentMethod(
|
||||
( Config ) => new Config( PaymentRequestPaymentMethod )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -277,25 +277,27 @@
|
|||
/**
|
||||
* @typedef {Object} StripeServerData
|
||||
*
|
||||
* @property {string} stripeTotalLabel The string used for payment
|
||||
* descriptor.
|
||||
* @property {string} publicKey The public api key for stripe
|
||||
* requests.
|
||||
* @property {boolean} allowPrepaidCard True means that prepaid cards
|
||||
* can be used for payment.
|
||||
* @property {Object} button Contains button styles
|
||||
* @property {string} button.type The type of button.
|
||||
* @property {string} button.theme The theme for the button.
|
||||
* @property {string} button.height The height (in pixels) for
|
||||
* the button.
|
||||
* @property {string} button.locale The locale to use for stripe
|
||||
* elements.
|
||||
* @property {boolean} inline_cc_form Whether stripe cc should use
|
||||
* inline cc
|
||||
* form or separate inputs.
|
||||
* @property {{[k:string]:CreditCardIcon}} icons Contains supported cc icons.
|
||||
* @property {boolean} allowSavedCards Used to indicate whether saved cards
|
||||
* can be used.
|
||||
* @property {string} stripeTotalLabel The string used for payment
|
||||
* descriptor.
|
||||
* @property {string} publicKey The public api key for stripe
|
||||
* requests.
|
||||
* @property {boolean} allowPrepaidCard True means that prepaid cards
|
||||
* can be used for payment.
|
||||
* @property {Object} button Contains button styles
|
||||
* @property {string} button.type The type of button.
|
||||
* @property {string} button.theme The theme for the button.
|
||||
* @property {string} button.height The height (in pixels) for
|
||||
* the button.
|
||||
* @property {string} button.locale The locale to use for stripe
|
||||
* elements.
|
||||
* @property {boolean} inline_cc_form Whether stripe cc should use
|
||||
* inline cc
|
||||
* form or separate inputs.
|
||||
* @property {{[k:string]:CreditCardIcon}} icons Contains supported cc icons.
|
||||
* @property {boolean} allowSavedCards Used to indicate whether saved cards
|
||||
* can be used.
|
||||
* @property {boolean} allowPaymentRequest True if merchant has enabled payment
|
||||
* request (Chrome/Apple Pay).
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,18 +86,19 @@ final class Stripe extends AbstractPaymentMethodType {
|
|||
*/
|
||||
public function get_payment_method_data() {
|
||||
return [
|
||||
'stripeTotalLabel' => $this->get_total_label(),
|
||||
'publicKey' => $this->get_publishable_key(),
|
||||
'allowPrepaidCard' => $this->get_allow_prepaid_card(),
|
||||
'button' => [
|
||||
'stripeTotalLabel' => $this->get_total_label(),
|
||||
'publicKey' => $this->get_publishable_key(),
|
||||
'allowPrepaidCard' => $this->get_allow_prepaid_card(),
|
||||
'button' => [
|
||||
'type' => $this->get_button_type(),
|
||||
'theme' => $this->get_button_theme(),
|
||||
'height' => $this->get_button_height(),
|
||||
'locale' => $this->get_button_locale(),
|
||||
],
|
||||
'inline_cc_form' => $this->get_inline_cc_form(),
|
||||
'icons' => $this->get_icons(),
|
||||
'allowSavedCards' => $this->get_allow_saved_cards(),
|
||||
'inline_cc_form' => $this->get_inline_cc_form(),
|
||||
'icons' => $this->get_icons(),
|
||||
'allowSavedCards' => $this->get_allow_saved_cards(),
|
||||
'allowPaymentRequest' => $this->get_allow_payment_request(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -144,6 +145,16 @@ final class Stripe extends AbstractPaymentMethodType {
|
|||
return apply_filters( 'wc_stripe_allow_prepaid_card', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if store allows Payment Request buttons - e.g. Apple Pay / Chrome Pay.
|
||||
*
|
||||
* @return bool True if merchant has opted into payment request.
|
||||
*/
|
||||
private function get_allow_payment_request() {
|
||||
$option = isset( $this->settings['payment_request'] ) ? $this->settings['payment_request'] : false;
|
||||
return filter_var( $option, FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the button type for the payment button.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue