forked from ratepay/php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.paymentInit.php
executable file
·34 lines (24 loc) · 1.27 KB
/
example.paymentInit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require __DIR__ . '/vendor/autoload.php';
require_once "ratepay_credentials.php";
/*************************************************
* The PaymentInit initializes a new transaction *
*************************************************/
// Building head model
$mbArr = new RatePAY\ModelBuilder('Head'); // If no parameter is set, 'head' model will be set by default
$mbArr->setArray([
'SystemId' => "Example",
'Credential' => [
'ProfileId' => PROFILE_ID,
'Securitycode' => SECURITYCODE
]
]);
$rb = new RatePAY\RequestBuilder(true); // true == Sandbox mode
$paymentInit = $rb->callPaymentInit($mbArr);
if (!$paymentInit->isSuccessful()) die("PaymentInit not successful");
// PaymentInit response object provides following methods:
// getTransactionId(); // Returns transaction id (unique transaction identifier) {string}
var_dump($paymentInit->getTransactionId());
/*********************************************************************************************************************************
* The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. *
*********************************************************************************************************************************/