Skip to content

Commit 023a444

Browse files
authored
Merge pull request #16 from PaymentHighway/pivo
Pivo and Siirto
2 parents c6a1ba4 + ed69911 commit 023a444

File tree

4 files changed

+317
-1
lines changed

4 files changed

+317
-1
lines changed

src/FormBuilder.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ class FormBuilder {
3636
static $SPH_WEBHOOK_CANCEL_URL = "sph-webhook-cancel-url";
3737
static $SPH_WEBHOOK_DELAY = "sph-webhook-delay";
3838
static $SPH_SHOW_PAYMENT_METHOD_SELECTOR = "sph-show-payment-method-selector";
39+
static $SPH_PHONE_NUMBER = "sph-phone-number";
40+
static $SPH_REFERENCE_NUMBER = "sph-reference-number";
41+
static $SPH_APP_URL = "sph-app-url";
42+
3943

4044
static $ADD_CARD_URI = "/form/view/add_card";
4145
static $PAYMENT_URI = "/form/view/pay_with_card";
4246
static $ADD_AND_PAY_URI = "/form/view/add_and_pay_with_card";
4347
static $CVC_AND_TOKEN_URI = "/form/view/pay_with_token_and_cvc";
4448
static $MOBILE_PAY_URI = "/form/view/mobilepay";
4549
static $MASTERPASS_PAY_URI = "/form/view/masterpass";
50+
static $SIIRTO_PAY_URI = "/form/view/siirto";
4651

4752

4853
private $method = 'POST';
@@ -411,6 +416,103 @@ public function generateMasterpassParameters($amount, $currency, $orderId, $desc
411416

412417
}
413418

419+
/**
420+
* Get parameters for Siirto request.
421+
*
422+
* @param string $amount The amount to pay in euro cents. Siirto supports only euros.
423+
* @param string $orderId A generated order ID, may for example be always unique or used multiple times for recurring transactions.
424+
* @param string $description Description of the payment shown in the form.
425+
* @param string $referenceNumber Reference number
426+
* @param string $phoneNumber User phone number with country code. Max AN 15. Optional
427+
* @param bool $exitIframeOnResult
428+
* @param string $webhookSuccessUrl The URL the PH server makes request after the transaction is handled. The payment itself may still be rejected.
429+
* @param string $webhookFailureUrl The URL the PH server makes request after a failure such as an authentication or connectivity error.
430+
* @param string $webhookCancelUrl The URL the PH server makes request after cancelling the transaction (clicking on the cancel button).
431+
* @param string $webhookDelay Delay for webhook in seconds. Between 0-900
432+
* @return Form
433+
*/
434+
public function generateSiirtoParameters($amount, $orderId, $description, $referenceNumber, $phoneNumber = null,
435+
$exitIframeOnResult = null, $webhookSuccessUrl = null, $webhookFailureUrl = null,
436+
$webhookCancelUrl = null, $webhookDelay = null)
437+
{
438+
$commonParameters = $this->createFormParameterArray();
439+
440+
$commonParameters[self::$SPH_AMOUNT] = $amount;
441+
$commonParameters[self::$SPH_CURRENCY] = "EUR";
442+
$commonParameters[self::$SPH_ORDER] = $orderId;
443+
$commonParameters[self::$SPH_REFERENCE_NUMBER] = $referenceNumber;
444+
445+
if(!is_null($exitIframeOnResult))
446+
$commonParameters[self::$SPH_EXIT_IFRAME_ON_RESULT] = $exitIframeOnResult;
447+
if(!is_null($phoneNumber))
448+
$commonParameters[self::$SPH_PHONE_NUMBER] = $phoneNumber;
449+
450+
$commonParameters = array_merge($commonParameters,
451+
$this->createWebhookParametersArray($webhookSuccessUrl, $webhookFailureUrl, $webhookCancelUrl, $webhookDelay));
452+
453+
ksort($commonParameters, SORT_DESC);
454+
455+
$commonParameters = $this->booleans2Text($commonParameters);
456+
457+
$signature = $this->createSecureSign(self::$SIIRTO_PAY_URI, $commonParameters);
458+
459+
$commonParameters[self::$DESCRIPTION] = $description;
460+
$commonParameters[self::$LANGUAGE] = $this->language;
461+
$commonParameters[self::$SIGNATURE] = $signature;
462+
463+
return new Form($this->method, $this->baseUrl, self::$SIIRTO_PAY_URI, $commonParameters);
464+
}
465+
466+
/**
467+
* Get parameters for Pivo request.
468+
*
469+
* @param string $amount The amount to pay in euro cents. Pivo supports only euros.
470+
* @param string $orderId A generated order ID, may for example be always unique or used multiple times for recurring transactions.
471+
* @param string $description Description of the payment shown in the form.
472+
* @param string $referenceNumber Reference number
473+
* @param string $phoneNumber User phone number with country code. Max AN 15. Optional
474+
* @param string $appUrl When used, Pivo tries to open application with this url. Optional.
475+
* @param bool $exitIframeOnResult
476+
* @param string $webhookSuccessUrl The URL the PH server makes request after the transaction is handled. The payment itself may still be rejected.
477+
* @param string $webhookFailureUrl The URL the PH server makes request after a failure such as an authentication or connectivity error.
478+
* @param string $webhookCancelUrl The URL the PH server makes request after cancelling the transaction (clicking on the cancel button).
479+
* @param string $webhookDelay Delay for webhook in seconds. Between 0-900
480+
* @return Form
481+
*/
482+
public function generatePivoParameters($amount, $orderId, $description, $referenceNumber = null, $phoneNumber = null, $appUrl = null,
483+
$exitIframeOnResult = null, $webhookSuccessUrl = null, $webhookFailureUrl = null,
484+
$webhookCancelUrl = null, $webhookDelay = null)
485+
{
486+
$commonParameters = $this->createFormParameterArray();
487+
488+
$commonParameters[self::$SPH_AMOUNT] = $amount;
489+
$commonParameters[self::$SPH_CURRENCY] = "EUR";
490+
$commonParameters[self::$SPH_ORDER] = $orderId;
491+
492+
if(!is_null($exitIframeOnResult))
493+
$commonParameters[self::$SPH_EXIT_IFRAME_ON_RESULT] = $exitIframeOnResult;
494+
if(!is_null($phoneNumber))
495+
$commonParameters[self::$SPH_PHONE_NUMBER] = $phoneNumber;
496+
if(!is_null($referenceNumber))
497+
$commonParameters[self::$SPH_REFERENCE_NUMBER] = $referenceNumber;
498+
if(!is_null($appUrl))
499+
$commonParameters[self::$SPH_APP_URL] = $appUrl;
500+
$commonParameters = array_merge($commonParameters,
501+
$this->createWebhookParametersArray($webhookSuccessUrl, $webhookFailureUrl, $webhookCancelUrl, $webhookDelay));
502+
503+
ksort($commonParameters, SORT_DESC);
504+
505+
$commonParameters = $this->booleans2Text($commonParameters);
506+
507+
$signature = $this->createSecureSign(self::$SIIRTO_PAY_URI, $commonParameters);
508+
509+
$commonParameters[self::$DESCRIPTION] = $description;
510+
$commonParameters[self::$LANGUAGE] = $this->language;
511+
$commonParameters[self::$SIGNATURE] = $signature;
512+
513+
return new Form($this->method, $this->baseUrl, self::$SIIRTO_PAY_URI, $commonParameters);
514+
}
515+
414516
/**
415517
* @param $webhookSuccessUrl
416518
* @param $webhookFailureUrl

src/PaymentApi.php

Lines changed: 66 additions & 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 = "20180426")
58+
public function __construct($serviceUrl, $signatureKeyId, $signatureSecret, $account, $merchant, $apiversion = "20180725")
5959
{
6060
$this->serviceUrl = $serviceUrl;
6161
$this->signatureKeyId = $signatureKeyId;
@@ -83,6 +83,7 @@ public function initTransaction()
8383
* @param $currency
8484
* @return Response
8585
* @throws \Httpful\Exception\ConnectionErrorException
86+
* @throws Model\Request\Exception
8687
*/
8788
public function commitFormTransaction($transactionId, $amount, $currency)
8889
{
@@ -104,6 +105,41 @@ public function debitTransaction($transactionId, Transaction $transaction)
104105
return $this->makeRequest(self::$METHOD_POST, $uri, $transaction);
105106
}
106107

108+
/**
109+
* Used to find out whether or not an uncommitted transaction succeeded, without actually committing (capturing) it.
110+
* @param string|UUID $transactionId
111+
* @return Response
112+
* @throws \Httpful\Exception\ConnectionErrorException
113+
*/
114+
public function transactionResult($transactionId)
115+
{
116+
$uri = '/transaction/' . $transactionId . '/result';
117+
return $this->makeRequest(self::$METHOD_GET, $uri);
118+
}
119+
120+
/**
121+
* Used to find out whether or not an Siirto transaction succeeded.
122+
* @param string|UUID $transactionId
123+
* @return Response
124+
* @throws \Httpful\Exception\ConnectionErrorException
125+
*/
126+
public function siirtoTransactionResult($transactionId)
127+
{
128+
$uri = '/transaction/' . $transactionId . '/siirto/result';
129+
return $this->makeRequest(self::$METHOD_GET, $uri);
130+
}
131+
132+
/**
133+
* Used to find out whether or not an Pivo transaction succeeded.
134+
* @param string|UUID $transactionId
135+
* @return Response
136+
* @throws \Httpful\Exception\ConnectionErrorException
137+
*/
138+
public function pivoTransactionResult($transactionId)
139+
{
140+
$uri = '/transaction/' . $transactionId . '/pivo/result';
141+
return $this->makeRequest(self::$METHOD_GET, $uri);
142+
}
107143

108144
/**
109145
* @param string $transactionId
@@ -117,6 +153,32 @@ public function revertTransaction($transactionId, $amount)
117153
return $this->makeRequest(self::$METHOD_POST, $uri, array('amount' => $amount));
118154
}
119155

156+
/**
157+
* @param string $transactionId
158+
* @param string $referenceNumber
159+
* @param string $amount
160+
* @return \Httpful\Response
161+
* @throws \Httpful\Exception\ConnectionErrorException
162+
*/
163+
public function revertSiirtoTransaction($transactionId, $referenceNumber, $amount)
164+
{
165+
$uri = '/transaction/' . $transactionId . '/siirto/revert';
166+
return $this->makeRequest(self::$METHOD_POST, $uri, array('reference_number' => $referenceNumber, 'amount' => $amount));
167+
}
168+
169+
/**
170+
* @param string $transactionId
171+
* @param string $referenceNumber
172+
* @param string $amount
173+
* @return \Httpful\Response
174+
* @throws \Httpful\Exception\ConnectionErrorException
175+
*/
176+
public function revertPivoTransaction($transactionId, $referenceNumber, $amount)
177+
{
178+
$uri = '/transaction/' . $transactionId . '/pivo/revert';
179+
return $this->makeRequest(self::$METHOD_POST, $uri, array('reference_number' => $referenceNumber, 'amount' => $amount));
180+
}
181+
120182
/**
121183
* @param string $transactionId
122184
* @return \Httpful\Response
@@ -156,6 +218,7 @@ public function searchByOrderId($orderId, $limit = null, $startDate = null, $end
156218
/**
157219
* @param $tokenizeId
158220
* @return \Httpful\Response
221+
* @throws \Httpful\Exception\ConnectionErrorException
159222
*/
160223
public function tokenize($tokenizeId)
161224
{
@@ -179,6 +242,7 @@ public function getReport($date)
179242
* @param string $date in format yyyyMMdd. The date to fetch the reconciliation report for.
180243
* @param bool $useDateProcessed Use the acquirer processed date instead of report received date. Might cause changes to the past
181244
* @return \Httpful\Response
245+
* @throws \Httpful\Exception\ConnectionErrorException
182246
*/
183247
public function fetchReconciliationReport($date, $useDateProcessed = false)
184248
{
@@ -226,6 +290,7 @@ private function createSecureSign($method, $uri, array $sphNameValuePairs = arra
226290
* @param $uri
227291
* @param null $body
228292
* @return \Httpful\Response
293+
* @throws \Httpful\Exception\ConnectionErrorException
229294
*/
230295
private function makeRequest($method, $uri, $body = null)
231296
{

tests/unit/FormBuilderTest.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,50 @@ public function PaymentWithMasterpassWithWebhook($method, $signatureKeyId, $sign
316316
$this->validateWebhookParameters($form->getParameters());
317317
}
318318

319+
/**
320+
* @dataProvider payWithSiirtoParameters
321+
* @test
322+
*/
323+
public function PaymentWithSiirto($method, $signatureKeyId, $signatureSecret, $account, $merchant, $baseUrl, $successUrl,
324+
$failureUrl, $cancelUrl, $language, $amount, $orderId, $description, $phoneNumber,
325+
$referenceNumber, $webhookSuccessUrl, $webhookFailureUrl, $webhookCancelUrl, $webhookDelay
326+
)
327+
{
328+
$formbuilder = new \Solinor\PaymentHighway\FormBuilder(
329+
$method, $signatureKeyId, $signatureSecret, $account,
330+
$merchant, $baseUrl, $successUrl, $failureUrl,
331+
$cancelUrl, $language
332+
);
333+
334+
$form = $formbuilder->generateSiirtoParameters($amount, $orderId, $description, $phoneNumber, $referenceNumber, null,
335+
$webhookSuccessUrl, $webhookFailureUrl, $webhookCancelUrl, $webhookDelay);
336+
337+
$this->validateWebhookParameters($form->getParameters());
338+
$this->assertCount(19, $form->getParameters());
339+
}
340+
341+
/**
342+
* @dataProvider payWithPivoParameters
343+
* @test
344+
*/
345+
public function PaymentWithPivo($method, $signatureKeyId, $signatureSecret, $account, $merchant, $baseUrl, $successUrl,
346+
$failureUrl, $cancelUrl, $language, $amount, $orderId, $description, $phoneNumber,
347+
$reference, $appUrl, $webhookSuccessUrl, $webhookFailureUrl, $webhookCancelUrl, $webhookDelay
348+
)
349+
{
350+
$formbuilder = new \Solinor\PaymentHighway\FormBuilder(
351+
$method, $signatureKeyId, $signatureSecret, $account,
352+
$merchant, $baseUrl, $successUrl, $failureUrl,
353+
$cancelUrl, $language
354+
);
355+
356+
$form = $formbuilder->generatePivoParameters($amount, $orderId, $description, $phoneNumber, $reference, $appUrl, null,
357+
$webhookSuccessUrl, $webhookFailureUrl, $webhookCancelUrl, $webhookDelay);
358+
359+
$this->validateWebhookParameters($form->getParameters());
360+
$this->assertCount(20, $form->getParameters());
361+
}
362+
319363
/**
320364
* @param array $parameters
321365
*/
@@ -457,6 +501,59 @@ public function payWithMobilePayWithOptionalParametersParameters()
457501
);
458502
}
459503

504+
/**
505+
* @return array
506+
*/
507+
public function payWithSiirtoParametersParameters()
508+
{
509+
return array(
510+
array(
511+
'POST',
512+
'testKey',
513+
'testSecret',
514+
'test',
515+
'test_merchantId',
516+
'https://v1-hub-staging.sph-test-solinor.com',
517+
'https://example.com/success',
518+
'https://example.com/failure',
519+
'https://example.com/cancel',
520+
'FI',
521+
'100',
522+
'123',
523+
'testitilaus',
524+
'1313',
525+
'+3581234567'
526+
)
527+
);
528+
}
529+
530+
/**
531+
* @return array
532+
*/
533+
public function payWithPivoParametersParameters()
534+
{
535+
return array(
536+
array(
537+
'POST',
538+
'testKey',
539+
'testSecret',
540+
'test',
541+
'test_merchantId',
542+
'https://v1-hub-staging.sph-test-solinor.com',
543+
'https://example.com/success',
544+
'https://example.com/failure',
545+
'https://example.com/cancel',
546+
'FI',
547+
'100',
548+
'123',
549+
'testitilaus',
550+
'1313',
551+
'+3581234567',
552+
'app://url'
553+
)
554+
);
555+
}
556+
460557
/**
461558
* @return array
462559
*/
@@ -535,6 +632,33 @@ public function payWithMasterpassWebhookParameters()
535632
);
536633
}
537634

635+
/**
636+
* @return array
637+
*/
638+
public function payWithSiirtoParameters()
639+
{
640+
$paymentParameters = $this->payWithSiirtoParametersParameters();
641+
return array(
642+
array_merge(
643+
$paymentParameters[0],
644+
$this->getWebhookParametersArray()
645+
)
646+
);
647+
}
648+
649+
/**
650+
* @return array
651+
*/
652+
public function payWithPivoParameters()
653+
{
654+
$paymentParameters = $this->payWithPivoParametersParameters();
655+
return array(
656+
array_merge(
657+
$paymentParameters[0],
658+
$this->getWebhookParametersArray()
659+
)
660+
);
661+
}
538662
private function getWebhookParametersArray()
539663
{
540664
return array(

0 commit comments

Comments
 (0)