クラス
GetBuyer
説明 説明
ファイル: src/API/GetBuyer.php
class GetBuyer extends ErrorStore
{
const INVALID_TOKEN = 'InvalidToken';
/**
* 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();
}
/**
* Gets buyer info post sign-in
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param string $token
* @return array
* @throws InvalidArgumentException Thrown by `getAmazonClient`.
*/
public function get($token) {
try {
$client = $this->module->getAmazonClient();
$result = $client->getBuyer($token);
if ($this->module->errors->hasError($result)) {
return $this->module->errors->getAmzErrorResponse($result, $this);
}
} catch (\Exception $e) {
return $this->module->errors->getErrorResponse(
GenericErrorStore::AMAZON_PAY_SDK_CLIENT_EXCEPTION,
[$e->getMessage()]
);
}
return $result;
}
/**
* Populates error store
*
* @see https://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-api-v2/buyer.html#error-codes
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
* @throws InvalidArgumentException Thrown if duplicate errorcodes exist.
*/
public function populate() {
$this->addError(new GenericError(
self::INVALID_TOKEN,
$this->getConstantNameByValue(self::INVALID_TOKEN),
400,
function ($message) {
return $message;
},
$this->getErrorCodeMap()[parent::INTERNAL_SERVER_ERROR]->message
));
}
}
- __construct — Sets `$module` member var with dependency injection.
- get — Gets buyer info post sign-in
- populate — Populates error store