Skip to content

Commit cf73125

Browse files
committed
Merge remote-tracking branch 'origin/master' into pivo
2 parents 135b036 + 366daea commit cf73125

File tree

7 files changed

+92
-67
lines changed

7 files changed

+92
-67
lines changed

src/Model/Card.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @package Solinor\PaymentHighway\Model
77
*/
88

9-
class Card implements \JsonSerializable
9+
class Card extends JsonSerializable
1010
{
1111
public $pan = null;
1212
public $expiry_year = null;
@@ -29,22 +29,4 @@ public function __construct( $pan, $expiry_year, $expiry_month, $cvc = null, $ve
2929
$this->cvc = $cvc;
3030
$this->verification = $verification;
3131
}
32-
33-
/**
34-
* Specify data which should be serialized to JSON
35-
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
36-
* @return mixed data which can be serialized by <b>json_encode</b>,
37-
* which is a value of any type other than a resource.
38-
* @since 5.4.0
39-
*/
40-
public function jsonSerialize()
41-
{
42-
$data = get_object_vars($this);
43-
44-
foreach($data as $key => $val)
45-
if($val === null)
46-
unset($data[$key]);
47-
48-
return $data;
49-
}
50-
}
32+
}

src/Model/JsonSerializable.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php namespace Solinor\PaymentHighway\Model;
2+
3+
class JsonSerializable implements \JsonSerializable
4+
{
5+
/**
6+
* Specify data which should be serialized to JSON
7+
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
8+
* @return mixed data which can be serialized by <b>json_encode</b>,
9+
* which is a value of any type other than a resource.
10+
* @since 5.4.0
11+
*/
12+
public function jsonSerialize()
13+
{
14+
$data = get_object_vars($this);
15+
16+
foreach($data as $key => $val)
17+
if($val === null)
18+
unset($data[$key]);
19+
20+
return $data;
21+
}
22+
}

src/Model/Request/Transaction.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @package Solinor\PaymentHighway\Model\Request
99
*/
1010

11-
class Transaction implements \JsonSerializable
11+
class Transaction extends \Solinor\PaymentHighway\Model\JsonSerializable
1212
{
1313
public $amount = null;
1414
public $currency = null;
@@ -17,21 +17,24 @@ class Transaction implements \JsonSerializable
1717

1818
public $token = null;
1919
public $card = null;
20+
public $splitting = null;
2021

2122
/**
2223
* @param int $amount
2324
* @param string $currency
2425
* @param Card|Token|null $request
2526
* @param bool $blocking
2627
* @param string $orderId
28+
* @param Splitting $splitting
2729
* @throws Exception
2830
*/
29-
public function __construct( $request, $amount, $currency, $blocking = true, $orderId = null )
31+
public function __construct( $request, $amount, $currency, $blocking = true, $orderId = null, $splitting = null )
3032
{
3133
$this->amount = $amount;
3234
$this->currency = $currency;
3335
$this->order = $orderId;
3436
$this->blocking = $blocking;
37+
$this->splitting = $splitting;
3538

3639
$this->setRequestByType($request);
3740
}
@@ -48,22 +51,4 @@ private function setRequestByType( $request )
4851
$this->card = $request;
4952
}
5053
}
51-
52-
/**
53-
* Specify data which should be serialized to JSON
54-
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
55-
* @return mixed data which can be serialized by <b>json_encode</b>,
56-
* which is a value of any type other than a resource.
57-
* @since 5.4.0
58-
*/
59-
public function jsonSerialize()
60-
{
61-
$data = get_object_vars($this);
62-
63-
foreach($data as $key => $val)
64-
if($val === null)
65-
unset($data[$key]);
66-
67-
return $data;
68-
}
69-
}
54+
}

src/Model/Splitting.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php namespace Solinor\PaymentHighway\Model;
2+
3+
/**
4+
* Class Splitting
5+
* Splits the payment into sub-merchant settlement and the main merchant commission. Requires separate activation.
6+
* @package Solinor\PaymentHighway\Model
7+
*/
8+
class Splitting extends JsonSerializable
9+
{
10+
public $merchant_id = null;
11+
public $amount = null;
12+
13+
/**
14+
* @param string $merchant_id Sub-merchant ID from the settlements provider. Not to be confused with the sph-merchant value.
15+
* @param int $amount The amount settled to the sub-merchant's account. The rest will be considered as the main merchant's commission. In the smallest currency unit. E.g. 99.99 € = 9999.
16+
*/
17+
public function __construct($merchant_id, $amount)
18+
{
19+
$this->merchant_id = $merchant_id;
20+
$this->amount = $amount;
21+
}
22+
}

src/Model/Token.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @package Solinor\PaymentHighway\Model
77
*/
88

9-
class Token implements \JsonSerializable
9+
class Token extends JsonSerializable
1010
{
1111
public $id = null;
1212
public $cvc = null;
@@ -20,22 +20,4 @@ public function __construct($id, $cvc = null)
2020
$this->id = $id;
2121
$this->cvc = $cvc;
2222
}
23-
24-
/**
25-
* Specify data which should be serialized to JSON
26-
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
27-
* @return mixed data which can be serialized by <b>json_encode</b>,
28-
* which is a value of any type other than a resource.
29-
* @since 5.4.0
30-
*/
31-
public function jsonSerialize()
32-
{
33-
$data = get_object_vars($this);
34-
35-
foreach($data as $key => $val)
36-
if($val === null)
37-
unset($data[$key]);
38-
39-
return $data;
40-
}
41-
}
23+
}

src/PaymentApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PaymentApi
5555
* @param string $merchant
5656
* @param string $apiversion
5757
*/
58-
public function __construct($serviceUrl, $signatureKeyId, $signatureSecret, $account, $merchant, $apiversion = "20160630")
58+
public function __construct($serviceUrl, $signatureKeyId, $signatureSecret, $account, $merchant, $apiversion = "20180426")
5959
{
6060
$this->serviceUrl = $serviceUrl;
6161
$this->signatureKeyId = $signatureKeyId;

tests/unit/PaymentApiTest.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Solinor\PaymentHighway\Model\Card;
44
use Solinor\PaymentHighway\Model\Request\Transaction;
5+
use Solinor\PaymentHighway\Model\Splitting;
56
use Solinor\PaymentHighway\PaymentApi;
67
use Solinor\PaymentHighway\Tests\TestBase;
78

@@ -72,7 +73,7 @@ public function initHandlerSuccessfully( PaymentApi $api )
7273
public function debitTransactionSuccess(PaymentApi $api, $transactionId )
7374
{
7475

75-
$card = $this->getValidCard();
76+
$card = $this->getValidCardTransactionRequest();
7677

7778
$response = $api->debitTransaction( $transactionId, $card)->body;
7879

@@ -192,9 +193,39 @@ public function getReportSuccess( PaymentApi $api )
192193
}
193194

194195
/**
195-
* @return Card
196+
* @depends paymentApiExists
197+
* @test
198+
* @param PaymentApi $api
199+
* @return string transactionId
200+
*/
201+
public function splittingDetailsAreReturnedInTransactionStatus(PaymentApi $api)
202+
{
203+
$transactionId = $api->initTransaction()->body->id;
204+
205+
$subMerchantId = "12345";
206+
$amountToSubMerchant = 90;
207+
208+
$splitting = new Splitting($subMerchantId, $amountToSubMerchant);
209+
210+
$transactionRequest = $this->getValidCardTransactionRequest($splitting);
211+
212+
$debitResponse = $api->debitTransaction($transactionId, $transactionRequest)->body;
213+
214+
$this->assertEquals('100', $debitResponse->result->code);
215+
216+
$statusResponse = $api->statusTransaction($transactionId)->body;
217+
218+
$this->assertEquals($subMerchantId, $statusResponse->transaction->splitting->merchant_id);
219+
$this->assertEquals($amountToSubMerchant, $statusResponse->transaction->splitting->amount);
220+
221+
return $transactionId;
222+
}
223+
224+
/**
225+
* @param Splitting $splitting
226+
* @return Transaction
196227
*/
197-
private function getValidCard()
228+
private function getValidCardTransactionRequest($splitting = null)
198229
{
199230
return new Transaction(
200231
new Card(
@@ -206,7 +237,8 @@ private function getValidCard()
206237
99,
207238
'EUR',
208239
true,
209-
self::$orderId
240+
self::$orderId,
241+
$splitting
210242
);
211243
}
212-
}
244+
}

0 commit comments

Comments
 (0)