Skip to content

Commit 3abdc21

Browse files
committed
rename vpos to card
1 parent 7ff19b7 commit 3abdc21

8 files changed

Lines changed: 49 additions & 48 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $flexpay = new Flexpay(
3939

4040
```php
4141
use Devscast\Flexpay\Data\Currency;
42-
use Devscast\Flexpay\Request\VposRequest;
42+
use Devscast\Flexpay\Request\CardRequest;
4343
use Devscast\Flexpay\Request\MobileRequest;
4444

4545
$mobile = new MobileRequest(
@@ -51,7 +51,7 @@ $mobile = new MobileRequest(
5151
callbackUrl: "your_website_webhook_url",
5252
);
5353

54-
$card = new VposRequest(
54+
$card = new CardRequest(
5555
amount: 10, // 10 USD
5656
currency: Currency::USD,
5757
reference: "your_unique_transaction_reference",

src/Client.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
namespace Devscast\Flexpay;
66

77
use Devscast\Flexpay\Exception\NetworkException;
8+
use Devscast\Flexpay\Request\CardRequest;
89
use Devscast\Flexpay\Request\MobileRequest;
910
use Devscast\Flexpay\Request\Request;
10-
use Devscast\Flexpay\Request\VposRequest;
11+
use Devscast\Flexpay\Response\CardResponse;
1112
use Devscast\Flexpay\Response\CheckResponse;
1213
use Devscast\Flexpay\Response\FlexpayResponse;
1314
use Devscast\Flexpay\Response\PaymentResponse;
14-
use Devscast\Flexpay\Response\VposResponse;
1515
use Symfony\Component\HttpClient\HttpClient;
1616
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
1717
use Symfony\Component\HttpClient\RetryableHttpClient;
@@ -89,14 +89,14 @@ public function mobile(MobileRequest $request): PaymentResponse
8989
*
9090
* @throws NetworkException
9191
*/
92-
public function vpos(VposRequest $request): VposResponse
92+
public function card(CardRequest $request): CardResponse
9393
{
9494
$request->setCredential($this->credential);
9595

9696
try {
97-
/** @var VposResponse $response */
97+
/** @var CardResponse $response */
9898
$response = $this->getMappedData(
99-
type: VposResponse::class,
99+
type: CardResponse::class,
100100
data: $this->http->request('POST', $this->environment->getVposAskUrl(), [
101101
'json' => $request->getPayload(),
102102
])->toArray()
@@ -111,11 +111,11 @@ public function vpos(VposRequest $request): VposResponse
111111
/**
112112
* @throws NetworkException
113113
*/
114-
public function pay(Request $request): PaymentResponse|VposResponse
114+
public function pay(Request $request): PaymentResponse|CardResponse
115115
{
116116
return match (true) {
117117
$request instanceof MobileRequest => $this->mobile($request),
118-
$request instanceof VposRequest => $this->vpos($request),
118+
$request instanceof CardRequest => $this->card($request),
119119
default => throw new \RuntimeException('Unsupported request')
120120
};
121121
}
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,45 @@
88
use Webmozart\Assert\Assert;
99

1010
/**
11-
* Class VposRequest.
11+
* Class CardRequest.
1212
*
1313
* @author bernard-ng <bernard@devscast.tech>
1414
*/
15-
final class VposRequest extends Request
15+
final class CardRequest extends Request
1616
{
1717
public function __construct(
1818
float $amount,
1919
string $reference,
2020
Currency $currency,
21+
string $description,
2122
string $callbackUrl,
22-
public readonly ?string $homeUrl,
23-
?string $description = null,
24-
?string $approveUrl = null,
25-
?string $cancelUrl = null,
26-
?string $declineUrl = null
23+
string $approveUrl,
24+
string $cancelUrl,
25+
string $declineUrl,
26+
public string $homeUrl,
2727
) {
28+
Assert::notEmpty($description, 'The description must be provided');
2829
Assert::notEmpty($approveUrl, 'The approve url must be provided');
30+
Assert::notEmpty($cancelUrl, 'The cancel url must be provided');
31+
Assert::notEmpty($declineUrl, 'The decline url must be provided');
32+
Assert::notEmpty($homeUrl, 'The home url must be provided');
33+
Assert::lengthBetween($reference, 1, 25, 'The reference must be between 1 and 25 characters');
2934

3035
parent::__construct($amount, $reference, $currency, $callbackUrl, $approveUrl, $description, $cancelUrl, $declineUrl);
3136
}
3237

38+
/**
39+
* Yeah, I know this is weird
40+
* But I'm not responsible for the API design.
41+
* so don't blame :D
42+
*/
3343
#[\Override]
3444
public function getPayload(): array
3545
{
3646
return [
3747
'amount' => $this->amount,
3848
'merchant' => $this->merchant,
39-
'authorization' => $this->authorization,
49+
'authorization' => sprintf('Bearer %s', $this->authorization),
4050
'reference' => $this->reference,
4151
'currency' => $this->currency->value,
4252
'callback_url' => $this->callbackUrl,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
use Devscast\Flexpay\Data\Status;
88

99
/**
10-
* Class VposResponse.
10+
* Class CardResponse.
1111
*
1212
* @author bernard-ng <bernard@devscast.tech>
1313
*/
14-
final class VposResponse extends FlexpayResponse
14+
final class CardResponse extends FlexpayResponse
1515
{
1616
public function __construct(
1717
public Status $code,

tests/ClientTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Devscast\Flexpay\Credential;
1010
use Devscast\Flexpay\Data\Currency;
1111
use Devscast\Flexpay\Data\Transaction;
12-
use Devscast\Flexpay\Request\VposRequest;
12+
use Devscast\Flexpay\Request\CardRequest;
1313
use Devscast\Flexpay\Request\MobileRequest;
14-
use Devscast\Flexpay\Response\VposResponse;
14+
use Devscast\Flexpay\Response\CardResponse;
1515
use Devscast\Flexpay\Response\CheckResponse;
1616
use Devscast\Flexpay\Response\PaymentResponse;
1717
use Symfony\Component\HttpClient\MockHttpClient;
@@ -41,23 +41,26 @@ private function getResponse(string $file): MockResponse
4141
return new MockResponse((string) file_get_contents(__DIR__ . '/fixtures/' . $file));
4242
}
4343

44-
public function testVpos(): void
44+
public function testCard(): void
4545
{
46-
$flexpay = $this->getFlexpay($this->getResponse('vpos_ask.json'));
47-
$request = new VposRequest(
46+
$flexpay = $this->getFlexpay($this->getResponse('card_success.json'));
47+
$request = new CardRequest(
4848
amount: 1,
4949
reference: 'ref',
5050
currency: Currency::USD,
51+
description: 'test',
5152
callbackUrl: 'http://localhost:8000/callback',
53+
approveUrl: 'http://localhost:8000/approve',
54+
cancelUrl: 'http://localhost:8000/cancel',
55+
declineUrl: 'http://localhost:8000/decline',
5256
homeUrl: 'http://localhost:8000/home',
53-
approveUrl: 'http://localhost:8000/approve'
5457
);
55-
$response = $flexpay->vpos($request);
58+
$response = $flexpay->card($request);
5659

57-
$this->assertInstanceOf(VposResponse::class, $response);
60+
$this->assertInstanceOf(CardResponse::class, $response);
5861
$this->assertTrue($response->isSuccessful());
59-
$this->assertEquals('6708a4708d470_1728619632', $response->orderNumber);
60-
$this->assertEquals('https://beta-cardpayment.flexpay.cd/vpos/pay/6708a4708d470_1728619632', $response->url);
62+
$this->assertEquals('O42iABI27568020268434827', $response->orderNumber);
63+
$this->assertEquals('https://gwvisa.flexpay.cd/checkout/bbba6b699af8a70e9cfa010d6d12dba5_670d206b7defb', $response->url);
6164
}
6265

6366
public function testSuccessCheck(): void

tests/EnvironmentTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testEnvironment(): void
3131
$this->assertEquals(Environment::SANDBOX, Environment::from('dev'));
3232
}
3333

34-
public function testGetVposAskUrl(): void
34+
public function testGetCardPaymentUrl(): void
3535
{
3636
$this->assertEquals(
3737
'https://cardpayment.flexpay.cd/v1.1/pay',
@@ -55,18 +55,6 @@ public function testGetMobilePaymentUrl(): void
5555
);
5656
}
5757

58-
public function testGetVposPaymentUrl(): void
59-
{
60-
$this->assertEquals(
61-
'https://cardpayment.flexpay.cd/vpos/pay/123456',
62-
$this->prod->getVposPaymentUrl('123456')
63-
);
64-
$this->assertEquals(
65-
'https://beta-cardpayment.flexpay.cd/vpos/pay/123456',
66-
$this->dev->getVposPaymentUrl('123456')
67-
);
68-
}
69-
7058
public function testGetCheckStatusUrl(): void
7159
{
7260
$this->assertEquals(

tests/fixtures/card_success.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"code": 0,
3+
"message": "Redirection en cours",
4+
"orderNumber": "O42iABI27568020268434827",
5+
"url": "https://gwvisa.flexpay.cd/checkout/bbba6b699af8a70e9cfa010d6d12dba5_670d206b7defb"
6+
}

tests/fixtures/vpos_ask.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)