-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
503 additions
and
467 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
use Olssonm\Swish\Callback; | ||
use Olssonm\Swish\Payment; | ||
use Olssonm\Swish\Refund; | ||
|
||
test('callback', function () { | ||
$paymentCallback = '{ | ||
"id": "5D59DA1B1632424E874DDB219AD54597", | ||
"payeePaymentReference": "0123456789", | ||
"paymentReference": "1E2FC19E5E5E4E18916609B7F8911C12", | ||
"callbackUrl": "https://example.com/api/swishcb/paymentrequests", | ||
"payerAlias": "4671234768", | ||
"payeeAlias": "1231181189", | ||
"amount": 100.00, | ||
"currency": "SEK", | ||
"message": "Kingston USB Flash Drive 8 GB", | ||
"status": "PAID", | ||
"dateCreated": "2019-01-02T14:29:51.092Z", | ||
"datePaid": "2019-01-02T14:29:55.093Z", | ||
"errorCode": null, | ||
"errorMessage": "" | ||
}'; | ||
|
||
$refundCallback = '{ | ||
"amount": "100.00", | ||
"originalPaymentReference": "5D59DA1B1632424E874DDB219AD54597", | ||
"dateCreated": "2020-10-29T13:40:27.950+0100", | ||
"payerPaymentReference": null, | ||
"payerAlias": "1231181189", | ||
"callbackUrl": "https://9036c2a41fe0.ngrok.io/callback", | ||
"currency": "SEK", | ||
"id": "136A8AA7052F42CCB8563C78AB54C66B", | ||
"payeeAlias": null, | ||
"status": "DEBITED" | ||
}'; | ||
|
||
$payment = Callback::parse($paymentCallback); | ||
$refund = Callback::parse($refundCallback); | ||
|
||
$this->assertInstanceOf(Payment::class, $payment); | ||
$this->assertEquals('5D59DA1B1632424E874DDB219AD54597', $payment->id); | ||
|
||
$this->assertInstanceOf(Refund::class, $refund); | ||
$this->assertEquals('5D59DA1B1632424E874DDB219AD54597', $refund->originalPaymentReference); | ||
$this->assertEquals('136A8AA7052F42CCB8563C78AB54C66B', $refund->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,97 @@ | ||
<?php | ||
|
||
use Olssonm\Swish\Callback; | ||
use Olssonm\Swish\Exceptions\CallbackDecodingException; | ||
use Olssonm\Swish\Exceptions\ClientException; | ||
use Olssonm\Swish\Exceptions\InvalidUuidException; | ||
use Olssonm\Swish\Exceptions\ServerException; | ||
use Olssonm\Swish\Exceptions\ValidationException; | ||
use Olssonm\Swish\Payment; | ||
use Olssonm\Swish\Refund; | ||
|
||
it('throws InvalidUuidException', function () { | ||
$this->expectException(InvalidUuidException::class); | ||
new Payment(['id' => 'invalid-uuid']); | ||
}); | ||
|
||
it('throws BadMethodCallException', function () { | ||
$this->expectException(\BadMethodCallException::class); | ||
|
||
$container = []; | ||
$client = get_mock_client(200, [], null, $container); | ||
$client->cancel(new Refund(['id' => '5D59DA1B1632424E874DDB219AD54597'])); | ||
}); | ||
|
||
it('throws ValidationException', function () { | ||
$payment = new Payment(); | ||
$payment->id = '5D59DA1B1632424E874DDB219AD54597'; | ||
$payment->amount = 100; | ||
$payment->currency = 'SEK'; | ||
$payment->payee = '123456789'; | ||
|
||
$container = []; | ||
$client = get_mock_client(422, [], '{ | ||
"id": "5D59DA1B1632424E874DDB219AD54597", | ||
"payeePaymentReference": "0123456789", | ||
"paymentReference": "1E2FC19E5E5E4E18916609B7F8911C12", | ||
"callbackUrl": "", | ||
"payerAlias": "4671234768", | ||
"payeeAlias": "1231181189", | ||
"amount": 100.00, | ||
"currency": "SEK", | ||
"message": "Kingston USB Flash Drive 8 GB", | ||
"status": "PAID", | ||
"dateCreated": "2019-01-02T14:29:51.092Z", | ||
"datePaid": "2019-01-02T14:29:55.093Z", | ||
"errorCode": "RP03", | ||
"errorMessage": "Callback URL is missing or does not use HTTPS." | ||
}', $container); | ||
|
||
try { | ||
$response = $client->create($payment); | ||
} catch (ValidationException $e) { | ||
$this->assertInstanceOf(ValidationException::class, $e); | ||
$this->assertEquals($e->getErrors()[0]->errorCode, 'RP03'); | ||
$this->assertEquals($e->getErrors()[0]->errorMessage, 'Callback URL is missing or does not use HTTPS.'); | ||
} | ||
|
||
$this->assertEquals(422, $container[0]['response']->getStatusCode()); | ||
$this->assertEquals('/swish-cpcapi/api/v2/paymentrequests/5D59DA1B1632424E874DDB219AD54597', $container[0]['request']->getUri()->getPath()); | ||
$this->assertEquals('PUT', $container[0]['request']->getMethod()); | ||
}); | ||
|
||
it('throws InvalidArgumentException', function () { | ||
$this->expectException(InvalidArgumentException::class); | ||
|
||
$container = []; | ||
$client = get_mock_client(429, [], null, $container); | ||
|
||
$client->create(new stdClass()); | ||
}); | ||
|
||
it('throws ClientException', function () { | ||
$this->expectException(ClientException::class); | ||
|
||
$container = []; | ||
$client = get_mock_client(429, [], null, $container); | ||
|
||
$client->create(new Payment()); | ||
}); | ||
|
||
it('throws ServerException', function () { | ||
$this->expectException(ServerException::class); | ||
|
||
$container = []; | ||
$client = get_mock_client(500, [], null, $container); | ||
$client->create(new Payment()); | ||
}); | ||
|
||
it('throws CallbackDecodingException on invalid', function () { | ||
$this->expectException(CallbackDecodingException::class); | ||
Callback::parse('invalid'); | ||
}); | ||
|
||
it('throws CallbackDecodingException on null', function () { | ||
$this->expectException(CallbackDecodingException::class); | ||
Callback::parse(null); | ||
}); |
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,83 @@ | ||
<?php | ||
|
||
use Olssonm\Swish\Payment; | ||
use Olssonm\Swish\PaymentResult; | ||
use Olssonm\Swish\Payout; | ||
use Olssonm\Swish\PayoutResult; | ||
use Olssonm\Swish\Refund; | ||
use Olssonm\Swish\RefundResult; | ||
use Olssonm\Swish\Util\Time; | ||
use Olssonm\Swish\Util\Uuid; | ||
|
||
// Make a full standard test against the MSS API with payments and refunds | ||
test('full chain of requests', function () { | ||
|
||
$client = get_real_client(); | ||
|
||
// New payment | ||
$payment = new Payment([ | ||
'amount' => 100, | ||
'paymentRefeference' => 'abc123', | ||
'currency' => 'SEK', | ||
'payee' => '123456789', | ||
'message' => 'Kingston USB Flash Drive 8 GB', | ||
'callbackUrl' => 'https://webhook.site/ee23acc8-0ad9-4c34-866e-ef8ef421d7d4', | ||
'payerAlias' => '4671234768', | ||
'payeeAlias' => '1231181189', | ||
]); | ||
$id = $payment->id; | ||
|
||
$response = $client->create($payment); | ||
$this->assertEquals(201, $client->getHistory()[0]['response']->getStatusCode()); | ||
$this->assertEquals($id, $response->id); | ||
$this->assertEquals(get_class($response), PaymentResult::class); | ||
|
||
// Get payment | ||
$response = $client->get(new Payment(['id' => $id])); | ||
$this->assertEquals(200, $client->getHistory()[1]['response']->getStatusCode()); | ||
$this->assertEquals($id, $response->id); | ||
$this->assertEquals(get_class($response), Payment::class); | ||
|
||
// Refund a payment | ||
$refund = new Refund([ | ||
'payerPaymentReference' => '0123456789', | ||
'originalPaymentReference' => 'abc123', | ||
'callbackUrl' => 'https://webhook.site/ee23acc8-0ad9-4c34-866e-ef8ef421d7d4', | ||
'amount' => '100', | ||
'currency' => 'SEK', | ||
'payerAlias' => '1234567839', | ||
'message' => 'Refund for Kingston SSD Drive 320 GB', | ||
]); | ||
$id = $refund->id; | ||
$response = $client->create($refund); | ||
$this->assertEquals(201, $client->getHistory()[2]['response']->getStatusCode()); | ||
$this->assertEquals($id, $response->id); | ||
$this->assertEquals(get_class($response), RefundResult::class); | ||
|
||
// Get a refund | ||
$response = $client->get(new Refund(['id' => $refund->id])); | ||
$this->assertEquals(200, $client->getHistory()[3]['response']->getStatusCode()); | ||
$this->assertEquals($refund->id, $response->id); | ||
$this->assertEquals(get_class($response), Refund::class); | ||
|
||
// Make payout | ||
$payout = new Payout([ | ||
'payoutInstructionUUID' => Uuid::make(), | ||
'payerPaymentReference' => 'Test', | ||
'signingCertificateSerialNumber' => $client->getCertificate()->getSerial(), | ||
'payerAlias' => '1234679304', | ||
'payeeAlias' => '1234679304', | ||
'payeeSSN' => '195810288083', | ||
'amount' => '100', | ||
'currency' => 'SEK', | ||
'payoutType' => 'PAYOUT', | ||
'message' => 'Test', | ||
'callbackUrl' => 'https://example.com/callback', | ||
'instructionDate' => Time::make(), | ||
]); | ||
|
||
$response = $client->create($payout); | ||
$this->assertEquals(201, $client->getHistory()[4]['response']->getStatusCode()); | ||
$this->assertEquals(get_class($response), PayoutResult::class); | ||
$this->assertEquals($payout->payoutInstructionUUID, $response->payoutInstructionUUID); | ||
}); |
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
Oops, something went wrong.