クラス
Checkout
Amazon checkout JS component
ソース ソース
ファイル: src/Components/AmazonCheckout/Checkout.php
class Checkout { const AMAZON_PAY_BUTTON_ID = 'AmazonPayButton'; const AMAZON_CHECKOUT_JS_SLUG = 'amazon-checkout'; const WCEXAAP_CHECKOUT_JS_SLUG = 'wcexaap-checkout'; /** * AmazonPay module instance * * @var AmazonPay */ private $module; /** * Sets `$module` member var * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module */ public function __construct(AmazonPay $module) { $this->module = $module; } /** * Returns variables that the Amazon checkout JS depends on * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array */ protected function getCheckoutInjectionVariables() { $opts = $this->module->getActingOpts(); return [ 'amzjsurl' => $opts['amzjsurl'], 'sandbox' => $opts['sandbox'], 'merchantId' => $opts['merchant_id'], 'ledgerCurrency' => $opts['ledgerCurrency'], 'checkoutLanguage' => $opts['checkoutLanguage'], 'publicKeyId' => $opts['public_key_id'], ]; } /** * Enqueues Amazon checkout JS * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $checkoutEndpoint * @param string $placement * @param string $productType * @return void */ public function load($checkoutEndpoint, $placement, $productType = 'PayAndShip') { $semantic = new Semantic(); $semantic->loadToastCss(); $semantic->loadTransitionCss(); $semantic->loadSemanticJS(); wp_enqueue_script( self::AMAZON_CHECKOUT_JS_SLUG, $this->module->getActingOpts()['amzjsurl'] . '/checkout.js', [], WCEXAAP_VERSION, false ); wp_enqueue_script( self::WCEXAAP_CHECKOUT_JS_SLUG, WCEXAAP_PLUGIN_URL . '/dist/checkout.js', [self::AMAZON_CHECKOUT_JS_SLUG], WCEXAAP_VERSION, true ); wp_localize_script( self::WCEXAAP_CHECKOUT_JS_SLUG, AmazonPay::L10N, array_merge( $this->module->getScriptInjectionVariables(), $this->getCheckoutInjectionVariables(), [ 'checkoutEndpoint' => $checkoutEndpoint, 'productType' => $productType, 'placement' => $placement, ] ) ); } /** * Returns AmazonPay button div * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return string */ public static function getAmazonPayButton() { return '<div id="' . self::AMAZON_PAY_BUTTON_ID . '"></div>'; } }
- __construct — Sets $module member var
- getAmazonPayButton — Returns AmazonPay button div
- getCheckoutInjectionVariables — Returns variables that the Amazon checkout JS depends on
- load — Enqueues Amazon checkout JS