Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreusch committed Jan 6, 2021
1 parent 7317606 commit fbc5aed
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
31 changes: 22 additions & 9 deletions Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public function createCheckoutSession($checkoutSession, $headers = null)
public function getCheckoutSession($checkoutSessionId, $headers = null)
{
$result = parent::getCheckoutSession($checkoutSessionId, $headers);

//$result['status']
return new CheckoutSession(json_decode($result['response'], true));
$response = json_decode($result['response'], true);
if ((int)$result['status'] !== 200) {
throw new AmazonPayException($response['message']);
}
return new CheckoutSession($response);
}

/**
Expand Down Expand Up @@ -97,13 +99,16 @@ public function completeCheckoutSession($checkoutSessionId, $paymentDetails, $he
* @param null $headers
*
* @return \AmazonPayApiSdkExtension\Struct\Charge|array|bool|string
* @throws AmazonPayException
*/
public function getCharge($chargeId, $headers = null)
{
$result = parent::getCharge($chargeId, $headers);

//$result['status']
return new Charge(json_decode($result['response'], true));
$response = json_decode($result['response'], true);
if ((int)$result['status'] !== 200) {
throw new AmazonPayException('getCharge failed: ' . $response['message'] . ' - ' . $response['reasonCode']);
}
return new Charge($response);
}

public function captureCharge($chargeId, $charge, $headers = null)
Expand Down Expand Up @@ -176,24 +181,32 @@ public function createCharge($charge, $headers = null)
* @param array|null $headers
*
* @return \AmazonPayApiSdkExtension\Struct\Refund
* @throws AmazonPayException
*/
public function getRefund($refundId, $headers = null)
{
$result = parent::getRefund($refundId, $headers);

return new Refund(json_decode($result['response'], true));
$response = json_decode($result['response'], true);
if ((int)$result['status'] !== 200) {
throw new AmazonPayException('getCharge failed: ' . $response['message'] . ' - ' . $response['reasonCode']);
}
return new Refund($response);
}

/**
* @param $buyerToken
* @param array|null $headers
*
* @return \AmazonPayApiSdkExtension\Struct\Buyer
* @throws AmazonPayException
*/
public function getBuyer($buyerToken, $headers = null)
{
$result = parent::getBuyer($buyerToken, $headers);

$response = json_decode($result['response'], true);
if ((int)$result['status'] !== 200) {
throw new AmazonPayException('getBuyer failed: ' . $response['message'] . ' - ' . $response['reasonCode']);
}
return new Buyer(json_decode($result['response'], true));
}

Expand Down
2 changes: 1 addition & 1 deletion Struct/MerchantMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setMerchantReferenceId($merchantReferenceId)
*/
public function getMerchantStoreName()
{
return $this->merchantStoreName;
return strlen($this->merchantStoreName)>50?substr($this->merchantStoreName, 0, 47).'...':$this->merchantStoreName;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Struct/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function getAmount()
}

/**
* @param string $amount
* @param string|float $amount
*
* @return Price
*/
public function setAmount($amount)
{
$this->amount = round($amount, 2);
$this->amount = number_format(round($amount, 2), 2, '.', '');

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mkreusch/amazon-pay-api-sdk-php-extension",
"description": "Add a convenience layer to the Amazon Pay PHP SDK",
"version": "0.1.0",
"version": "0.2.0",
"require": {
"php": ">=5.5.0",
"amzn/amazon-pay-api-sdk-php": ">=2.0.0"
Expand Down

0 comments on commit fbc5aed

Please sign in to comment.