Skip to content

Commit 5fe93f2

Browse files
authored
Merge pull request #184 from unzerdev/CC-803/add-twint
[CC-803] [CC-697] Add twint class.
2 parents 432763d + d8c68ec commit 5fe93f2

File tree

5 files changed

+102
-2
lines changed

5 files changed

+102
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Click To Pay payment method is added to Java SDK.
1212
### Added
1313

1414
* Added `\UnzerSDK\Resources\PaymentTypes\ClickToPay` payment method.
15-
* Added tests for Click To Pay
16-
15+
* Added `\UnzerSDK\Resources\PaymentTypes\Twint` payment method.
1716

1817
## [3.5.0](https://github.com/unzerdev/php-sdk/compare/3.4.1..3.5.0)
1918

src/Constants/IdStrings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class IdStrings
4949
public const SEPA_DIRECT_DEBIT_GUARANTEED = 'ddg';
5050
public const SEPA_DIRECT_DEBIT_SECURED = 'dds';
5151
public const SOFORT = 'sft';
52+
public const TWINT = 'twt';
5253
public const WECHATPAY = 'wcp';
5354

5455
// Resources
@@ -89,6 +90,7 @@ class IdStrings
8990
self::SEPA_DIRECT_DEBIT_GUARANTEED,
9091
self::SEPA_DIRECT_DEBIT_SECURED,
9192
self::SOFORT,
93+
self::TWINT,
9294
self::WECHATPAY,
9395
];
9496
}

src/Resources/PaymentTypes/Twint.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\PaymentTypes;
4+
5+
use UnzerSDK\Traits\HasAccountInformation;
6+
7+
class Twint extends BasePaymentType
8+
{
9+
use HasAccountInformation;
10+
}

src/Services/ResourceService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use UnzerSDK\Resources\PaymentTypes\PayU;
2020
use UnzerSDK\Resources\PaymentTypes\PostFinanceCard;
2121
use UnzerSDK\Resources\PaymentTypes\PostFinanceEfinance;
22+
use UnzerSDK\Resources\PaymentTypes\Twint;
2223
use UnzerSDK\Resources\TransactionTypes\Chargeback;
2324
use UnzerSDK\Unzer;
2425
use UnzerSDK\Interfaces\ResourceServiceInterface;
@@ -886,6 +887,9 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType
886887
case IdStrings::SOFORT:
887888
$paymentType = new Sofort();
888889
break;
890+
case IdStrings::TWINT:
891+
$paymentType = new Twint();
892+
break;
889893
case IdStrings::WECHATPAY:
890894
$paymentType = new Wechatpay();
891895
break;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/** @noinspection PhpUnhandledExceptionInspection */
4+
/** @noinspection PhpDocMissingThrowsInspection */
5+
/**
6+
* This class defines integration tests to verify interface and
7+
* functionality of the payment method Twint.
8+
*/
9+
10+
namespace UnzerSDK\test\integration\PaymentTypes;
11+
12+
use UnzerSDK\Constants\ApiResponseCodes;
13+
use UnzerSDK\Exceptions\UnzerApiException;
14+
use UnzerSDK\Resources\PaymentTypes\BasePaymentType;
15+
use UnzerSDK\Resources\PaymentTypes\Twint;
16+
use UnzerSDK\Resources\TransactionTypes\Charge;
17+
use UnzerSDK\test\BaseIntegrationTest;
18+
19+
class TwintTest extends BaseIntegrationTest
20+
{
21+
protected const testClass = Twint::class;
22+
23+
protected function setUp(): void
24+
{
25+
$this->markTestSkipped('Skipped by default as setup is missing for integration tests.');
26+
}
27+
28+
/**
29+
* Verify twint can be created.
30+
*
31+
* @test
32+
*/
33+
public function typeShouldBeCreatableAndFetchable(): BasePaymentType
34+
{
35+
$paymentType = $this->unzer->createPaymentType($this->createTypeInstance());
36+
$this->assertInstanceOf(self::testClass, $paymentType);
37+
$this->assertNotNull($paymentType->getId());
38+
39+
/** @var Twint $fetchedTwint */
40+
$fetchedTwint = $this->unzer->fetchPaymentType($paymentType->getId());
41+
$this->assertInstanceOf(self::testClass, $fetchedTwint);
42+
$this->assertEquals($paymentType->expose(), $fetchedTwint->expose());
43+
$this->assertNotEmpty($fetchedTwint->getGeoLocation()->getClientIp());
44+
45+
return $fetchedTwint;
46+
}
47+
48+
/**
49+
* Verify twint is chargeable.
50+
*
51+
* @test
52+
*
53+
* @depends typeShouldBeCreatableAndFetchable
54+
*/
55+
public function twintShouldBeAbleToCharge(BasePaymentType $paymentType): Charge
56+
{
57+
$charge = $this->unzer->charge(100.0, 'EUR', $paymentType, self::RETURN_URL);
58+
$this->assertNotNull($charge);
59+
$this->assertNotEmpty($charge->getId());
60+
$this->assertNotEmpty($charge->getRedirectUrl());
61+
62+
return $charge;
63+
}
64+
65+
/**
66+
* Verify twint is not authorizable.
67+
*
68+
* @test
69+
*
70+
* @depends typeShouldBeCreatableAndFetchable
71+
*/
72+
public function twintShouldNotBeAuthorizable(BasePaymentType $paymentType): void
73+
{
74+
$this->expectException(UnzerApiException::class);
75+
$this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED);
76+
77+
$this->unzer->authorize(100.0, 'EUR', $paymentType, self::RETURN_URL);
78+
}
79+
80+
public function createTypeInstance(): BasePaymentType
81+
{
82+
$class = self::testClass;
83+
return new $class();
84+
}
85+
}

0 commit comments

Comments
 (0)