Skip to content

Commit ce3aed2

Browse files
authored
Merge pull request #173 from unzerdev/CC-673/googlepay
Cc 673/googlepay
2 parents 4d8b80b + 24f5c8c commit ce3aed2

File tree

12 files changed

+804
-0
lines changed

12 files changed

+804
-0
lines changed

src/Constants/IdStrings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class IdStrings
2424
public const CARD = 'crd';
2525
public const EPS = 'eps';
2626
public const GIROPAY = 'gro';
27+
public const GOOGLE_PAY = 'gop';
2728
public const HIRE_PURCHASE_DIRECT_DEBIT = 'hdd';
2829
public const IDEAL = 'idl';
2930
public const INSTALLMENT_SECURED = 'ins';
@@ -63,6 +64,7 @@ class IdStrings
6364
self::CARD,
6465
self::EPS,
6566
self::GIROPAY,
67+
self::GOOGLE_PAY,
6668
self::HIRE_PURCHASE_DIRECT_DEBIT,
6769
self::IDEAL,
6870
self::INSTALLMENT_SECURED,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\EmbeddedResources\GooglePay;
4+
5+
use stdClass;
6+
use UnzerSDK\Adapter\HttpAdapterInterface;
7+
use UnzerSDK\Resources\AbstractUnzerResource;
8+
9+
class IntermediateSigningKey extends AbstractUnzerResource
10+
{
11+
/**
12+
* @var SignedKey $signedKey
13+
*/
14+
protected $signedKey;
15+
16+
/**
17+
* @var string[] $signedKey
18+
*/
19+
protected $signatures;
20+
21+
public function getSignedKey(): ?SignedKey
22+
{
23+
return $this->signedKey;
24+
}
25+
26+
public function setSignedKey(SignedKey $signedKey): IntermediateSigningKey
27+
{
28+
$this->signedKey = $signedKey;
29+
return $this;
30+
}
31+
32+
public function getSignatures(): array
33+
{
34+
return $this->signatures;
35+
}
36+
37+
public function setSignatures(array $signatures): IntermediateSigningKey
38+
{
39+
$this->signatures = $signatures;
40+
return $this;
41+
}
42+
43+
public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void
44+
{
45+
parent::handleResponse($response, $method);
46+
47+
if (isset($response->signedKey)) {
48+
$this->signedKey = new SignedKey();
49+
$this->signedKey->handleResponse($response->signedKey);
50+
}
51+
}
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\EmbeddedResources\GooglePay;
4+
5+
use UnzerSDK\Resources\AbstractUnzerResource;
6+
7+
class SignedKey extends AbstractUnzerResource
8+
{
9+
/**
10+
* @var string $keyExpiration
11+
*/
12+
protected $keyExpiration;
13+
14+
/**
15+
* @var string $keyValue
16+
*/
17+
protected $keyValue;
18+
19+
/**
20+
* @param string $keyExpiration
21+
* @param string $keyValue
22+
*/
23+
public function __construct(?string $keyExpiration = null, ?string $keyValue = null)
24+
{
25+
$this->keyExpiration = $keyExpiration;
26+
$this->keyValue = $keyValue;
27+
}
28+
29+
public function getKeyExpiration(): string
30+
{
31+
return $this->keyExpiration;
32+
}
33+
34+
public function setKeyExpiration(string $keyExpiration): SignedKey
35+
{
36+
$this->keyExpiration = $keyExpiration;
37+
return $this;
38+
}
39+
40+
public function getKeyValue(): string
41+
{
42+
return $this->keyValue;
43+
}
44+
45+
public function setKeyValue(string $keyValue): SignedKey
46+
{
47+
$this->keyValue = $keyValue;
48+
return $this;
49+
}
50+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\EmbeddedResources\GooglePay;
4+
5+
use UnzerSDK\Resources\AbstractUnzerResource;
6+
7+
class SignedMessage extends AbstractUnzerResource
8+
{
9+
/** @var string */
10+
protected $tag;
11+
12+
/** @var string */
13+
protected $ephemeralPublicKey;
14+
15+
/** @var string */
16+
protected $encryptedMessage;
17+
18+
/**
19+
* @param string $tag
20+
* @param string $ephemeralPublicKey
21+
* @param string $encryptedMessage
22+
*/
23+
public function __construct(string $tag = null, string $ephemeralPublicKey = null, string $encryptedMessage = null)
24+
{
25+
$this->tag = $tag;
26+
$this->ephemeralPublicKey = $ephemeralPublicKey;
27+
$this->encryptedMessage = $encryptedMessage;
28+
}
29+
30+
public function getTag(): string
31+
{
32+
return $this->tag;
33+
}
34+
35+
public function setTag(string $tag): SignedMessage
36+
{
37+
$this->tag = $tag;
38+
return $this;
39+
}
40+
41+
public function getEphemeralPublicKey(): string
42+
{
43+
return $this->ephemeralPublicKey;
44+
}
45+
46+
public function setEphemeralPublicKey(string $ephemeralPublicKey): SignedMessage
47+
{
48+
$this->ephemeralPublicKey = $ephemeralPublicKey;
49+
return $this;
50+
}
51+
52+
public function getEncryptedMessage(): string
53+
{
54+
return $this->encryptedMessage;
55+
}
56+
57+
public function setEncryptedMessage(string $encryptedMessage): SignedMessage
58+
{
59+
$this->encryptedMessage = $encryptedMessage;
60+
return $this;
61+
}
62+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\PaymentTypes;
4+
5+
use stdClass;
6+
use UnzerSDK\Adapter\HttpAdapterInterface;
7+
use UnzerSDK\Resources\EmbeddedResources\GooglePay\IntermediateSigningKey;
8+
use UnzerSDK\Resources\EmbeddedResources\GooglePay\SignedMessage;
9+
use UnzerSDK\Traits\CanAuthorize;
10+
use UnzerSDK\Traits\CanDirectCharge;
11+
12+
/**
13+
* Represents Google Pay type. It requires data from payment method token returned by Google in the `PaymentData`.
14+
* These data are used to create the payment type on the Unzer API.
15+
*/
16+
class Googlepay extends BasePaymentType
17+
{
18+
use CanDirectCharge;
19+
use CanAuthorize;
20+
21+
/**
22+
* @var string $protocolVersion
23+
*/
24+
protected $protocolVersion;
25+
26+
/**
27+
* @var string $signature
28+
*/
29+
protected $signature;
30+
31+
/**
32+
* @var IntermediateSigningKey $intermediateSigningKey
33+
*/
34+
protected $intermediateSigningKey;
35+
36+
/** @var SignedMessage $signedMessage */
37+
protected $signedMessage;
38+
39+
/** @var string $number */
40+
private $number;
41+
42+
/** @var string $expiryDate */
43+
private $expiryDate;
44+
45+
/**
46+
* @param string $protocolVersion
47+
* @param string $signature
48+
* @param IntermediateSigningKey $intermediateSigningKey
49+
* @param string $signedMessage
50+
*/
51+
public function __construct(
52+
?string $protocolVersion = null,
53+
?string $signature = null,
54+
?IntermediateSigningKey $intermediateSigningKey = null,
55+
?SignedMessage $signedMessage = null
56+
) {
57+
$this->protocolVersion = $protocolVersion;
58+
$this->signature = $signature;
59+
$this->intermediateSigningKey = $intermediateSigningKey;
60+
$this->signedMessage = $signedMessage;
61+
}
62+
63+
public static function getResourceName(): string
64+
{
65+
return 'googlepay';
66+
}
67+
68+
/**
69+
* @inheritDoc
70+
*/
71+
public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void
72+
{
73+
parent::handleResponse($response, $method);
74+
75+
if (isset($response->intermediateSigningKey)) {
76+
$this->intermediateSigningKey = new IntermediateSigningKey();
77+
$this->intermediateSigningKey->handleResponse($response->intermediateSigningKey);
78+
}
79+
}
80+
81+
public function getNumber(): string
82+
{
83+
return $this->number;
84+
}
85+
86+
protected function setNumber(string $number): Googlepay
87+
{
88+
$this->number = $number;
89+
return $this;
90+
}
91+
92+
public function getExpiryDate(): string
93+
{
94+
return $this->expiryDate;
95+
}
96+
97+
protected function setExpiryDate(string $expiryDate): Googlepay
98+
{
99+
$this->expiryDate = $expiryDate;
100+
return $this;
101+
}
102+
103+
public function getProtocolVersion(): ?string
104+
{
105+
return $this->protocolVersion;
106+
}
107+
108+
public function setProtocolVersion(?string $protocolVersion): Googlepay
109+
{
110+
$this->protocolVersion = $protocolVersion;
111+
return $this;
112+
}
113+
114+
public function getSignature(): ?string
115+
{
116+
return $this->signature;
117+
}
118+
119+
public function setSignature(?string $signature): Googlepay
120+
{
121+
$this->signature = $signature;
122+
return $this;
123+
}
124+
125+
public function getIntermediateSigningKey(): ?IntermediateSigningKey
126+
{
127+
return $this->intermediateSigningKey;
128+
}
129+
130+
public function setIntermediateSigningKey(?IntermediateSigningKey $intermediateSigningKey): Googlepay
131+
{
132+
$this->intermediateSigningKey = $intermediateSigningKey;
133+
return $this;
134+
}
135+
136+
public function getSignedMessage(): ?SignedMessage
137+
{
138+
return $this->signedMessage;
139+
}
140+
141+
public function setSignedMessage(?SignedMessage $signedMessage): Googlepay
142+
{
143+
$this->signedMessage = $signedMessage;
144+
return $this;
145+
}
146+
}

src/Services/ResourceService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use UnzerSDK\Exceptions\UnzerApiException;
1111
use UnzerSDK\Resources\Config;
1212
use UnzerSDK\Resources\PaymentTypes\Applepay;
13+
use UnzerSDK\Resources\PaymentTypes\Googlepay;
1314
use UnzerSDK\Resources\PaymentTypes\Klarna;
1415
use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit;
1516
use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment;
@@ -820,6 +821,9 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType
820821
case IdStrings::GIROPAY:
821822
$paymentType = new Giropay();
822823
break;
824+
case IdStrings::GOOGLE_PAY:
825+
$paymentType = new Googlepay();
826+
break;
823827
case IdStrings::HIRE_PURCHASE_DIRECT_DEBIT:
824828
case IdStrings::INSTALLMENT_SECURED:
825829
$paymentType = new InstallmentSecured();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"protocolVersion": "ECv2",
3+
"signature": "signature-xyz\u003d",
4+
"intermediateSigningKey": {
5+
"signedKey": {
6+
"keyExpiration": "1542394027316",
7+
"keyValue": "key-value-xyz\\u003d\\u003d\"}"
8+
},
9+
"signatures": [
10+
"signature1"
11+
]
12+
},
13+
"signedMessage": {
14+
"tag": "001 Cryptogram 3ds",
15+
"ephemeralPublicKey": "ephemeralPublicKey-xyz\\u003d\"",
16+
"encryptedMessage": "encryptedMessage-xyz\""
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": "s-gop-q0nucec6itwe",
3+
"method": "card",
4+
"recurring": false,
5+
"geoLocation": {
6+
"clientIp": "0:0:0:0:0:0:0:1",
7+
"countryIsoA2": ""
8+
},
9+
"number": "518834******0003",
10+
"expiryDate": "10/2025",
11+
"processing": {
12+
"uniqueId": "31HA07BC8127DC45EE6946C3B070FF71",
13+
"shortId": "5550.0369.6888",
14+
"traceId": "24c0a2ecbe3d54a838c76444d4bdcd1f"
15+
}
16+
}

test/Fixtures/jsonData/googlePay/googlepayToken.json

Whitespace-only changes.

0 commit comments

Comments
 (0)