-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/order-metafields-api
Conflicts: RELEASE_NOTES.md
- Loading branch information
Showing
12 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\Payments; | ||
|
||
use BigCommerce\ApiV3\Api\V3ApiBase; | ||
use BigCommerce\ApiV3\ResourceModels\Order\Order; | ||
use BigCommerce\ApiV3\ResponseModels\Payment\AcceptedPaymentMethodsResponse; | ||
use BigCommerce\ApiV3\ResponseModels\Payment\PaymentAccessTokenResponse; | ||
use GuzzleHttp\RequestOptions; | ||
|
||
class PaymentsProcessingApi extends V3ApiBase | ||
{ | ||
private const PAYMENTS_ENDPOINT = 'payments/'; | ||
private const ACCESS_TOKENS_ENDPOINT = self::PAYMENTS_ENDPOINT . 'access_tokens'; | ||
private const PAYMENT_METHODS_ENDPOINT = self::PAYMENTS_ENDPOINT . 'methods'; | ||
|
||
public function createToken(Order $order): PaymentAccessTokenResponse | ||
{ | ||
$response = $this->getClient()->getRestClient()->post( | ||
self::ACCESS_TOKENS_ENDPOINT, | ||
[ | ||
RequestOptions::JSON => json_encode($order), | ||
] | ||
); | ||
|
||
return new PaymentAccessTokenResponse($response); | ||
} | ||
|
||
public function paymentMethods(int $orderId): AcceptedPaymentMethodsResponse | ||
{ | ||
$response = $this->getClient()->getRestClient()->get( | ||
self::PAYMENT_METHODS_ENDPOINT, | ||
[ | ||
RequestOptions::QUERY => [ | ||
'order_id' => $orderId, | ||
] | ||
] | ||
); | ||
|
||
return new AcceptedPaymentMethodsResponse($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Order; | ||
|
||
class Order | ||
{ | ||
public int $id; | ||
public bool $is_recurring; | ||
|
||
public function __construct(int $id, string $is_recurring) | ||
{ | ||
$this->id = $id; | ||
$this->is_recurring = $is_recurring; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/BigCommerce/ResourceModels/Payment/PaymentAccessToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Payment; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\ResourceModel; | ||
|
||
class PaymentAccessToken extends ResourceModel | ||
{ | ||
public string $id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Payment; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\ResourceModel; | ||
|
||
class PaymentMethod extends ResourceModel | ||
{ | ||
public string $id; | ||
public string $name; | ||
public array $stored_instruments; | ||
public array $supported_instruments; | ||
public bool $test_mode; | ||
public string $type; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/BigCommerce/ResponseModels/Payment/AcceptedPaymentMethodsResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResponseModels\Payment; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Payment\PaymentMethod; | ||
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse; | ||
|
||
class AcceptedPaymentMethodsResponse extends PaginatedResponse | ||
{ | ||
/** | ||
* @return PaymentMethod[] | ||
*/ | ||
public function getMethods(): array | ||
{ | ||
return $this->getData(); | ||
} | ||
|
||
protected function resourceClass(): string | ||
{ | ||
return PaymentMethod::class; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/BigCommerce/ResponseModels/Payment/PaymentAccessTokenResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResponseModels\Payment; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Payment\PaymentAccessToken; | ||
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse; | ||
use stdClass; | ||
|
||
class PaymentAccessTokenResponse extends SingleResourceResponse | ||
{ | ||
private PaymentAccessToken $token; | ||
|
||
public function getToken(): PaymentAccessToken | ||
{ | ||
return $this->token; | ||
} | ||
|
||
protected function addData(stdClass $rawData): void | ||
{ | ||
$this->token = new PaymentAccessToken($rawData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace BigCommerce\Tests\Payments; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Order\Order; | ||
use BigCommerce\Tests\BigCommerceApiTest; | ||
|
||
class PaymentsProcessingApiTest extends BigCommerceApiTest | ||
{ | ||
public function testCanCreatePaymentToken(): void | ||
{ | ||
$this->setReturnData('payments__create_payment_access_token.json', 201); | ||
$order = new Order(1, false); | ||
|
||
$token = $this->getApi()->payments()->createToken($order)->getToken(); | ||
$this->assertEquals('abcdefg', $token->id); | ||
} | ||
|
||
public function testCanGetPaymentMethodsForOrder(): void | ||
{ | ||
$this->setReturnData('payments__get_accepted_payment_methods.json'); | ||
$methods = $this->getApi()->payments()->paymentMethods(123)->getMethods(); | ||
|
||
$this->assertCount(1, $methods); | ||
$this->assertEquals('stripe.card', $methods[0]->id); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/BigCommerce/responses/payments__create_payment_access_token.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"id": "abcdefg" | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/BigCommerce/responses/payments__get_accepted_payment_methods.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": "stripe.card", | ||
"name": "Stripe", | ||
"test_mode": true, | ||
"type": "card", | ||
"supported_instruments": [ | ||
{ | ||
"instrument_type": "VISA", | ||
"verification_value_required": true | ||
}, | ||
{ | ||
"instrument_type": "MASTERCARD", | ||
"verification_value_required": true | ||
}, | ||
{ | ||
"instrument_type": "AMEX", | ||
"verification_value_required": true | ||
}, | ||
{ | ||
"instrument_type": "DISCOVER", | ||
"verification_value_required": true | ||
}, | ||
{ | ||
"instrument_type": "JCB", | ||
"verification_value_required": true | ||
}, | ||
{ | ||
"instrument_type": "DINERS_CLUB", | ||
"verification_value_required": true | ||
}, | ||
{ | ||
"instrument_type": "STORED_CARD", | ||
"verification_value_required": true | ||
} | ||
], | ||
"stored_instruments": [ | ||
{ | ||
"type": "stored_card", | ||
"brand": "VISA", | ||
"expiry_month": 9, | ||
"expiry_year": 2020, | ||
"issuer_identification_number": "424242", | ||
"last_4": "4242", | ||
"token": "050a1e5c982e5905288ec5ec33f292772762033a0704f46fccb16bf1940b51ef", | ||
"is_default": true | ||
} | ||
] | ||
} | ||
], | ||
"meta": {} | ||
} |