クラス
MemberLoginPage
Member page login view. Login with Amazon
ソース ソース
ファイル: src/Views/MemberLoginPage/MemberLoginPage.php
class MemberLoginPage { /** * Slug name for our entry js script */ const LOGIN_JS_SLUG = 'wcexaap-member-page-login'; /** * AmazonPay module instance * * @var AmazonPay */ private $module; /** * Sets `$module` member var with dependency injection. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module */ public function __construct(AmazonPay $module) { $this->module = $module; } /** * Registers member login page hook for Amazon Pay login button * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function init() { if (!$this->module->isAmazonClientUsable()) { return; } if ($this->module->getActingOpts()['use_social_login'] === 'off') { return; } add_action('usces_action_login_page_inform', [$this, 'loginButton']); } /** * Enqueues necessary assets for this view. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function load() { wp_enqueue_style( 'wcexaap-login-page', WCEXAAP_PLUGIN_URL . '/src/Views/MemberLoginPage/style.css', [], WCEXAAP_VERSION ); wp_enqueue_script( Checkout::AMAZON_CHECKOUT_JS_SLUG, $this->module->getActingOpts()['amzjsurl'] . '/checkout.js', [], WCEXAAP_VERSION, false ); wp_enqueue_script( self::LOGIN_JS_SLUG, WCEXAAP_PLUGIN_URL . '/dist/memberPageLogin.js', [Checkout::AMAZON_CHECKOUT_JS_SLUG], WCEXAAP_VERSION, true ); wp_localize_script(self::LOGIN_JS_SLUG, AmazonPay::L10N, $this->getInjectionVariables()); } /** * Returns sign-in payload for Amazon Pay login button * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array * @throws InvalidArgumentException Thrown by `getActingOpts`. */ public function getSignInPayload() { return [ 'signInReturnUrl' => $this->module->redirectRoutes->createPublicQueryUrl( '/loginWithAmazon', USCES_MEMBER_URL ), 'storeId' => $this->module->getActingOpts()['client_id'], 'signInScopes' => ['email'], ]; } /** * Returns variables used by Amazon Pay sign-in JS * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array */ public function getInjectionVariables() { $opts = $this->module->getActingOpts(); $payload = json_encode($this->getSignInPayload(), JSON_UNESCAPED_SLASHES); return [ 'merchantId' => $opts['merchant_id'], 'ledgerCurrency' => $opts['ledgerCurrency'], 'sandbox' => $opts['sandbox'], 'checkoutLanguage' => $opts['checkoutLanguage'], 'buttonColor' => $opts['buttonColor'], 'signInConfig' => [ 'payloadJSON' => $payload, 'signature' => $this->module->getAmazonClient()->generateButtonSignature($payload), 'publicKeyId' => $opts['public_key_id'], ], ]; } /** * Amazon login button * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function loginButton() { /** * Filters the message shown above the Amazon Pay login button on the 会員ログイン page * * @important * @param string $text Default: 'Amazonアカウントで新規会員登録を完了している方は下のボタンでログインしてください。' */ $infomessage = apply_filters( 'wcexaap_filter_member_login_page_info_message', __('For customers who created their account with Amazon, please use the button below to login.', 'wcexaap') ); $this->load(); ?> <div id="wcexaap-button-wrapper"> <div class="info-message"> <?php echo $infomessage ?> </div> <div id="<?php echo esc_attr(Checkout::AMAZON_PAY_BUTTON_ID); ?>"></div> </div> <?php } }
- __construct — Sets $module member var with dependency injection.
- getInjectionVariables — Returns variables used by Amazon Pay sign-in JS
- getSignInPayload — Returns sign-in payload for Amazon Pay login button
- init — Registers member login page hook for Amazon Pay login button
- load — Enqueues necessary assets for this view.
- loginButton — Amazon login button