クラス
IPN
IPN API
ソース ソース
ファイル: src/Admin/API/IPN.php
class IPN extends ErrorStore { const URL_EMPTY = 'urlEmpty4000'; const URL_INVALID = 'urlInvalid4001'; /** * AmazonPay module object * * @var AmazonPay */ private $module; /** * Sets `$module` member var with dependency injection. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module * @return void */ public function __construct(AmazonPay $module) { $this->module = $module; parent::__construct(); $this->populate(); } /** * Registers site URL as IPN URL on seller central * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param array $args * @param array $payload * @return array */ public function register($args, $payload) { $url = $payload['ipnEndpoint']; if (empty($url)) { return $this->getErrorResponse(self::URL_EMPTY); } $response = (new EndpointSetter($this->module))->set($url); if ((int)$response['ResponseStatus'] !== 200) { if (isset($response['Error']['Code'])) { if ($response['Error']['Code'] === 'InvalidArgumentsClientError') { return $this->getErrorResponse(self::URL_INVALID, [$response['Error']['Message']]); } } return $this->getErrorResponse(self::INTERNAL_SERVER_ERROR); } $opts = $this->module->getActingOpts(); $opts['ipn_endpoint'] = $url; $opts['ipn_registered'] = true; $this->module->updateActingOpts($opts); return 'success'; } /** * Populates error store * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void * @throws InvalidArgumentException Thrown if duplicate errorcodes exist. */ public function populate() { $this->addError(new GenericError( self::URL_EMPTY, self::URL_EMPTY, 400, 'URL parameter is empty', __('Please enter the site URL.', 'wcexaap') )); $this->addError(new GenericError( self::URL_INVALID, self::URL_INVALID, 400, function ($message) { return $message; }, __('Please enter a valid URL.', 'wcexaap') )); } }
- __construct — Sets $module member var with dependency injection.
- populate — Populates error store
- register — Registers site URL as IPN URL on seller central