-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added payment sessions support (#233)
- Loading branch information
1 parent
4310ef9
commit a9b413f
Showing
8 changed files
with
223 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Checkout\Payments\Sessions; | ||
|
||
use Checkout\Common\Address; | ||
|
||
class Billing | ||
{ | ||
/** | ||
* @var Address | ||
*/ | ||
public $address; | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Checkout\Payments\Sessions; | ||
|
||
use Checkout\ApiClient; | ||
use Checkout\AuthorizationType; | ||
use Checkout\CheckoutApiException; | ||
use Checkout\CheckoutConfiguration; | ||
use Checkout\Client; | ||
|
||
class PaymentSessionsClient extends Client | ||
{ | ||
|
||
const PAYMENT_SESSIONS = "payment-sessions"; | ||
|
||
public function __construct(ApiClient $apiClient, CheckoutConfiguration $configuration) | ||
{ | ||
parent::__construct($apiClient, $configuration, AuthorizationType::$secretKey); | ||
} | ||
|
||
/** | ||
* @param PaymentSessionsRequest $paymentSessionsRequest | ||
* @return array | ||
* @throws CheckoutApiException | ||
*/ | ||
public function createPaymentSessions(PaymentSessionsRequest $paymentSessionsRequest) | ||
{ | ||
return $this->apiClient->post(self::PAYMENT_SESSIONS, $paymentSessionsRequest, $this->sdkAuthorization()); | ||
} | ||
|
||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Checkout\Payments\Sessions; | ||
|
||
use Checkout\Common\CustomerRequest; | ||
|
||
class PaymentSessionsRequest | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
public $amount; | ||
|
||
/** | ||
* @var string value of Currency | ||
*/ | ||
public $currency; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $reference; | ||
|
||
/** | ||
* @var Billing | ||
*/ | ||
public $billing; | ||
|
||
/** | ||
* @var CustomerRequest | ||
*/ | ||
public $customer; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $success_url; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $failure_url; | ||
} |
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
42 changes: 42 additions & 0 deletions
42
test/Checkout/Tests/Payments/Sessions/PaymentSessionsClientTest.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,42 @@ | ||
<?php | ||
|
||
namespace Checkout\Tests\Payments\Sessions; | ||
|
||
use Checkout\CheckoutApiException; | ||
use Checkout\Payments\Sessions\PaymentSessionsClient; | ||
use Checkout\Payments\Sessions\PaymentSessionsRequest; | ||
use Checkout\PlatformType; | ||
use Checkout\Tests\UnitTestFixture; | ||
|
||
class PaymentSessionsClientTest extends UnitTestFixture | ||
{ | ||
/** | ||
* @var PaymentSessionsClient | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function init() | ||
{ | ||
$this->initMocks(PlatformType::$default); | ||
$this->client = new PaymentSessionsClient($this->apiClient, $this->configuration); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws CheckoutApiException | ||
*/ | ||
public function shouldCreatePaymentSessions() | ||
{ | ||
|
||
$this->apiClient | ||
->method("post") | ||
->willReturn("response"); | ||
|
||
$response = $this->client->createPaymentSessions(new PaymentSessionsRequest()); | ||
$this->assertNotNull($response); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
test/Checkout/Tests/Payments/Sessions/PaymentSessionsIntegrationTest.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,78 @@ | ||
<?php | ||
|
||
namespace Checkout\Tests\Payments\Sessions; | ||
|
||
use Checkout\CheckoutApiException; | ||
use Checkout\CheckoutArgumentException; | ||
use Checkout\CheckoutAuthorizationException; | ||
use Checkout\CheckoutException; | ||
use Checkout\Common\Currency; | ||
use Checkout\Common\CustomerRequest; | ||
use Checkout\Payments\Sessions\Billing; | ||
use Checkout\Payments\Sessions\PaymentSessionsRequest; | ||
use Checkout\PlatformType; | ||
use Checkout\Tests\SandboxTestFixture; | ||
|
||
class PaymentSessionsIntegrationTest extends SandboxTestFixture | ||
{ | ||
/** | ||
* @before | ||
* @throws CheckoutAuthorizationException | ||
* @throws CheckoutArgumentException | ||
* @throws CheckoutException | ||
*/ | ||
public function before() | ||
{ | ||
$this->init(PlatformType::$default); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws CheckoutApiException | ||
*/ | ||
public function shouldCreatePaymentsSessions() | ||
{ | ||
$request = $this->createPaymentSessionsRequest(); | ||
|
||
$response = $this->checkoutApi->getPaymentSessionsClient()->createPaymentSessions($request); | ||
|
||
$this->assertResponse( | ||
$response, | ||
"id", | ||
"amount", | ||
"locale", | ||
"currency", | ||
"payment_methods", | ||
"_links", | ||
"_links.self" | ||
); | ||
|
||
foreach ($response["payment_methods"] as $payment_method) { | ||
$this->assertResponse( | ||
$payment_method, | ||
"type" | ||
); | ||
} | ||
} | ||
|
||
private function createPaymentSessionsRequest() | ||
{ | ||
$billing = new Billing(); | ||
$billing->address = $this->getAddress(); | ||
|
||
$customer = new CustomerRequest(); | ||
$customer->name = "John Smith"; | ||
$customer->email = "john.smith@example.com"; | ||
|
||
$paymentSessionsRequest = new PaymentSessionsRequest(); | ||
$paymentSessionsRequest->amount = 2000; | ||
$paymentSessionsRequest->currency = Currency::$GBP; | ||
$paymentSessionsRequest->reference = "ORD-123A"; | ||
$paymentSessionsRequest->billing = $billing; | ||
$paymentSessionsRequest->customer = $customer; | ||
$paymentSessionsRequest->success_url = "https://example.com/payments/success"; | ||
$paymentSessionsRequest->failure_url = "https://example.com/payments/failure"; | ||
|
||
return $paymentSessionsRequest; | ||
} | ||
} |
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