クラス
LinePay
ソース ソース
ファイル: src/LinePay.php
class LinePay extends Module { /** * Guzzle client for LINE Pay API requests * * @var Api\Client */ public $api; /** * Routes object * * @var Routes\Routes */ public $routes; /** * Client-facing error store * * @var Errors\ClientErrorStore */ public $clientErrorStore; /** * Admin-facing error store * * @var Error\AdminErrorStore */ public $adminErrorStore; /** * Constructs settlement module * * @author Evan D Shaw <evandanielshaw@gmail.com> * @inheritDoc */ public function __construct() { $cptmc = new CptmClient( 'ALP001', WCEX_LINEPAY_VERSION, WCEX_LINEPAY_PLUGIN_FILE, 'https://api.aivec.co.jp/cptmp/v1/getProvidersList/ALP001' ); $cptmc->init(); parent::__construct( Config\Constants::PAYMENT_NAME, Config\Constants::ACTING, Config\Constants::ACTING_FLAG, [ 'shipped' => ['once'], 'data' => ['once'], 'service' => ['once'], ], Config\Constants::ALLOWED_CURRENCIES, false, $cptmc, true ); } /** * Initializes LINE Pay * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void * @throws InvalidArgumentException Thrown by `getActingOpts`. */ public function init() { $this->clientErrorStore = new Errors\ClientErrorStore($this); $this->adminErrorStore = new Errors\AdminErrorStore($this); $this->clientErrorStore->populate(); $this->adminErrorStore->populate(); $opts = $this->getActingOpts(); $this->api = new Api\Client( $this, $opts['sandbox'] === true ? Config\Constants::SANDBOX_API : Config\Constants::LIVE_API, $opts['channel_id'], $opts['channel_secret_key'] ); $ready = $this->ready(); add_action('init', function () use ($ready) { if ($ready === true) { $this->routes = new Routes\Routes($this); $this->routes->dispatcher->listen(); } }, 11); (new DeliveryPage($this))->init(); (new Views\ConfirmPage\ConfirmPage($this))->init()->addHooks(); if (is_admin()) { // create settlement module settings page (new Admin\SettlementSettings($this))->init(); if ($ready === true) { (new Admin\Views\OrderEditPage\OrderEditPage($this))->addHooks(); (new Admin\Views\OrderListPage($this))->init()->addHooks(); } } usces_register_action( 'wcexalpCompletePurchase', 'get', 'wcexalpCompletePurchase', null, function () { $confirm = new Api\Confirm($this); $confirm->init()->addHooks(); $confirm->middleware($_GET); // route guards $confirm->fulfillOrder($_GET); } ); } /** * Returns confirm redirect URL * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return string */ public static function getConfirmRedirectUrl() { $url = add_query_arg(['wcexalpCompletePurchase' => 1], USCES_CART_URL); return $url; } /** * Filter default acting options with Module specific opts * * @inheritDoc * @author Evan D Shaw <evandanielshaw@gmail.com> * @param array $opts * @return array */ public function filterActingOpts($opts) { $opts['channel_id'] = isset($opts['channel_id']) ? $opts['channel_id'] : ''; $opts['channel_secret_key'] = isset($opts['channel_secret_key']) ? $opts['channel_secret_key'] : ''; $linepay_locale = 'en'; $locale = get_locale(); switch ($locale) { case 'ja': $linepay_locale = 'ja'; break; case 'th': $linepay_locale = 'th'; break; case 'ko_KR': $linepay_locale = 'ko'; break; case 'zh_CN': case 'zh_HK': case 'zh_SG': $linepay_locale = 'zh_CN'; break; case 'zh_TW': $linepay_locale = 'zh_TW'; break; } $opts['allowed_locales'] = ['ja', 'ko', 'en', 'zh_CN', 'zh_TW', 'th']; $opts['locale'] = $linepay_locale; $opts['allowed_currencies'] = Config\Constants::ALLOWED_CURRENCIES; return $opts; } /** * Variables to be injected into any LINE Pay script * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return array */ public function getScriptInjectionVars() { return array_merge( $this->routes->getScriptInjectionVariables(), $this->clientErrorStore->getScriptInjectionVariables(), ['reactDomNode' => Config\Constants::REACT_DOM_NODE] ); } }
- __construct — Constructs settlement module
- filterActingOpts — Filter default acting options with Module specific opts
- getConfirmRedirectUrl — Returns confirm redirect URL
- getScriptInjectionVars — Variables to be injected into any LINE Pay script
- init — Initializes LINE Pay