└── PHP-sample-code-PT2
├── Follow-up-transaction
├── query-transaction.php
├── Void.php
├── Capture.php
└── Refund.php
├── Token-based-transaction
├── Delete-token.php
├── query-token.php
└── Create-payment-with-token.php
├── Invoice
├── Cancel-invoice-Post.php
├── Get-invoice-status-with-Post.php
├── Cancel-invoice-Put.php
├── Get-invoice-status.php
├── Create-invoice.php
└── Create-invoice-with-token.php
├── Result.php
├── Hosted-payment-page
├── Create-payment-page-Tokenization.php
├── Create-payment-page-Tokenization-optional.php
├── create-payment-page-HostedPaymentPage-framed.php
└── Create-Payment-Page-HostedPaymentPage.php
├── Own-Form - Payment Request
└── Create-Own-Form - Payment-Request.php
├── Managed-Form - Payment-Request
├── Send-managed-form.php
└── Create-managed-Form-Payment-Request.php
├── Wallet-payments
├── Samsung-pay.php
└── Apple-pay.php
└── Paytabs-plugin.php
/PHP-sample-code-PT2/Follow-up-transaction/query-transaction.php:
--------------------------------------------------------------------------------
1 | "TST2104800080101"
8 | ];
9 | $page = $plugin->send_api_request($request_url, $data);
10 | print_r($page);
11 | exit();
12 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Token-based-transaction/Delete-token.php:
--------------------------------------------------------------------------------
1 | "2C4651BE67A3EA30C6B791F8618B78B0"
8 | ];
9 | $page = $plugin->send_api_request($request_url, $data);
10 | print_r($page);
11 | exit();
12 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Token-based-transaction/query-token.php:
--------------------------------------------------------------------------------
1 | "2C4651BE67A3EA30C6B791F8618B78B0"
8 | ];
9 | $page = $plugin->send_api_request($request_url, $data);
10 | print_r($page);
11 | exit();
12 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Invoice/Cancel-invoice-Post.php:
--------------------------------------------------------------------------------
1 | $invoice_id
9 | ];
10 |
11 | $page = $plugin->send_api_request($request_url, $data);
12 | print_r('the invoice details is');
13 | print_r('
');
14 | print_r($page);
15 |
16 | exit();
17 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Invoice/Get-invoice-status-with-Post.php:
--------------------------------------------------------------------------------
1 | $invoice_id
9 | ];
10 |
11 | $page = $plugin->send_api_request($request_url, $data);
12 | print_r('the invoice details is');
13 | print_r('
');
14 | print_r($page);
15 |
16 | exit();
17 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Invoice/Cancel-invoice-Put.php:
--------------------------------------------------------------------------------
1 | send_api_request($request_url, $data, $request_method);
11 | print_r('the request result is');
12 | print_r('
');
13 | print_r($page);
14 |
15 | exit();
16 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Invoice/Get-invoice-status.php:
--------------------------------------------------------------------------------
1 | send_api_request($request_url, $data, $request_method);
11 | print_r('the invoice details is');
12 | print_r('
');
13 | print_r($page);
14 |
15 | exit();
16 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Follow-up-transaction/Void.php:
--------------------------------------------------------------------------------
1 | "void",
8 | "tran_class" => "ecom",
9 | "cart_id" => "cart_66666",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => 130,
12 | "cart_description" => "shopping Cart",
13 | "tran_ref" => "TST2105400086891" //the Auth tran_ref you want to Void it
14 | ];
15 | $page = $plugin->send_api_request($request_url, $data);
16 | print_r($page);
17 | exit();
18 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Follow-up-transaction/Capture.php:
--------------------------------------------------------------------------------
1 | "capture",
8 | "tran_class" => "ecom",
9 | "cart_id" => "cart_66666",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => 130,
12 | "cart_description" => "shopping Cart",
13 | "tran_ref" => "TST2105400087083" //the Auth tran_ref you want to capture it
14 | ];
15 | $page = $plugin->send_api_request($request_url, $data);
16 | print_r($page);
17 | exit();
18 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Follow-up-transaction/Refund.php:
--------------------------------------------------------------------------------
1 | "refund",
8 | "tran_class" => "ecom",
9 | "cart_id" => "cart_66666",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => 130,
12 | "cart_description" => "shopping Cart",
13 | "tran_ref" => "TST2105600089368" //the Capture tran_ref you want to refund it
14 | ];
15 | $page = $plugin->send_api_request($request_url, $data);
16 | print_r($page);
17 | exit();
18 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Token-based-transaction/Create-payment-with-token.php:
--------------------------------------------------------------------------------
1 | "capture",
8 | "tran_class" => "recurring",
9 | "cart_id" => "cart_444441",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => 120,
12 | "cart_description" => "Description of the items/services",
13 | "token" => "2C4651BE67A3EA30C6B791F8618B78B0", //token you received in the create page with token request
14 | "tran_ref" => "TST2105600089454", // trans_ref you received in the create page with token request
15 | "hide_shipping" => true,
16 | "paypage_lang" => "en",
17 | ];
18 | $page = $plugin->send_api_request($request_url, $data);
19 | print_r($page);
20 | exit();
21 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Result.php:
--------------------------------------------------------------------------------
1 | ');
14 | print_r($response_data);
15 |
16 | //
17 |
18 | echo "
Transaction reference: {$transRef}
";
19 |
20 |
21 | /** Local Verify PayTabs response By signature calculation: Option 1 */
22 |
23 | echo "Local Payment validation
";
24 |
25 | $is_valid = $plugin->is_valid_redirect($response_data);
26 |
27 | if (!$is_valid) {
28 | die('Not a valid PayTabs response');
29 | }
30 |
31 | //a
32 |
33 | $is_success = $response_data['respStatus'] === 'A';
34 | if ($is_success) {
35 | echo 'Payment succeed
';
36 | print_r($response_data);
37 | } else {
38 | echo 'Payment failed
';
39 | }
40 |
41 |
42 | /** Verify PayTabs response By sending new request: Option 2 */
43 |
44 | echo "Remote Payment validation
";
45 |
46 | $request_url = 'payment/query';
47 | $data = [
48 | "tran_ref" => $transRef
49 | ];
50 | $verify_result = $plugin->send_api_request($request_url, $data);
51 | $is_success = $verify_result['payment_result']['response_status'] === 'A';
52 | if ($is_success) {
53 | echo 'Payment succeed
';
54 | print_r($verify_result);
55 | } else {
56 | echo 'Payment failed
';
57 | }
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Invoice/Create-invoice.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/new/invoice';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => "950",
12 | "cart_id" => "Test Cart",
13 | "cart_description" => "Test Description",
14 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
15 | "hide_shipping" => true,
16 | "invoice" => [
17 | "shipping_charges" => 0,
18 | "extra_charges" => 0,
19 | "extra_discount" => 0,
20 | "total" => 0,
21 | "line_items" => [
22 | [
23 | "sku" => "sku",
24 | "description" => "desc",
25 | "url" => "https://webhook.site/92ac6a52-256d-434b-bde8-94b1e73d3aa1",
26 | "unit_cost" => 950,
27 | "quantity" => 1,
28 | "net_total" => 950,
29 | "discount_rate" => 0,
30 | "discount_amount" => 0,
31 | "tax_rate" => 0,
32 | "tax_total" => 0,
33 | "total" => 950
34 | ]
35 | ]
36 | ]
37 | ];
38 | $page = $plugin->send_api_request($request_url, $data);
39 | print_r('your invoice id is' . $page['invoice_id']);
40 | print_r('
');
41 | print_r("go to your invoice");
42 |
43 | exit();
44 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Invoice/Create-invoice-with-token.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/new/invoice';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "tokenise" => 2,
11 | "cart_currency" => "EGP",
12 | "cart_amount" => "950",
13 | "cart_id" => "Test Cart",
14 | "cart_description" => "Test Description",
15 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
16 | "hide_shipping" => true,
17 | "invoice" => [
18 | "shipping_charges" => 0,
19 | "extra_charges" => 0,
20 | "extra_discount" => 0,
21 | "total" => 0,
22 | "line_items" => [
23 | [
24 | "sku" => "sku",
25 | "description" => "desc",
26 | "url" => "https://webhook.site/92ac6a52-256d-434b-bde8-94b1e73d3aa1",
27 | "unit_cost" => 950,
28 | "quantity" => 1,
29 | "net_total" => 950,
30 | "discount_rate" => 0,
31 | "discount_amount" => 0,
32 | "tax_rate" => 0,
33 | "tax_total" => 0,
34 | "total" => 950
35 | ]
36 | ]
37 | ]
38 | ];
39 | $page = $plugin->send_api_request($request_url, $data);
40 | print_r('your invoice id is' . $page['invoice_id']);
41 | print_r('
');
42 | print_r("go to your invoice");
43 |
44 | exit();
45 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Hosted-payment-page/Create-payment-page-Tokenization.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/request';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "tokenise" => "2",
11 | "cart_id" => "cart_11111",
12 | "cart_currency" => "EGP",
13 | "cart_amount" => 1000,
14 | "cart_description" => "Description of the items/services",
15 | "paypage_lang" => "en",
16 | "show_save_card" => false,
17 | "callback" => "https://webhook.site/730acce0-e54e-4522-8a45-f9b8e44624b6", // Nullable - Must be HTTPS, otherwise no post data from paytabs
18 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
19 | "customer_details" => [
20 | "name" => "first last",
21 | "email" => "email@domain.com",
22 | "phone" => "0522222222",
23 | "street1" => "address street",
24 | "city" => "dubai",
25 | "state" => "du",
26 | "country" => "AE",
27 | "zip" => "12345"
28 | ],
29 | "shipping_details" => [
30 | "name" => "name1 last1",
31 | "email" => "email1@domain.com",
32 | "phone" => "971555555555",
33 | "street1" => "street2",
34 | "city" => "dubai",
35 | "state" => "dubai",
36 | "country" => "AE",
37 | "zip" => "54321"
38 | ]
39 | ];
40 |
41 | $page = $plugin->send_api_request($request_url, $data);
42 | header('Location:' . $page['redirect_url']); /* Redirect browser */
43 | exit();
44 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Hosted-payment-page/Create-payment-page-Tokenization-optional.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/request';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "tokenise" => "2",
11 | "cart_id" => "cart_11111",
12 | "cart_currency" => "EGP",
13 | "cart_amount" => 1000,
14 | "cart_description" => "Description of the items/services",
15 | "paypage_lang" => "en",
16 | "show_save_card" => true,
17 | "callback" => "https://webhook.site/730acce0-e54e-4522-8a45-f9b8e44624b6", // Nullable - Must be HTTPS, otherwise no post data from paytabs
18 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
19 | "customer_details" => [
20 | "name" => "first last",
21 | "email" => "email@domain.com",
22 | "phone" => "0522222222",
23 | "street1" => "address street",
24 | "city" => "dubai",
25 | "state" => "du",
26 | "country" => "AE",
27 | "zip" => "12345"
28 | ],
29 | "shipping_details" => [
30 | "name" => "name1 last1",
31 | "email" => "email1@domain.com",
32 | "phone" => "971555555555",
33 | "street1" => "street2",
34 | "city" => "dubai",
35 | "state" => "dubai",
36 | "country" => "AE",
37 | "zip" => "54321"
38 | ]
39 | ];
40 | $page = $plugin->send_api_request($request_url, $data);
41 | header('Location:' . $page['redirect_url']); /* Redirect browser */
42 | exit();
43 |
44 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Hosted-payment-page/create-payment-page-HostedPaymentPage-framed.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/request';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "cart_id" => "cart_11111",
11 | "cart_currency" => "EGP",
12 | "cart_amount" => 1000,
13 | "cart_description" => "Description of the items/services",
14 | "paypage_lang" => "en",
15 | "callback" => "https://webhook.site/730acce0-e54e-4522-8a45-f9b8e44624b6", // Nullable - Must be HTTPS, otherwise no post data from paytabs
16 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
17 | "customer_details" => [
18 | "name" => "first last",
19 | "email" => "email@domain.com",
20 | "phone" => "0522222222",
21 | "street1" => "address street",
22 | "city" => "dubai",
23 | "state" => "du",
24 | "country" => "AE",
25 | "zip" => "12345"
26 | ],
27 | "shipping_details" => [
28 | "name" => "name1 last1",
29 | "email" => "email1@domain.com",
30 | "phone" => "971555555555",
31 | "street1" => "street2",
32 | "city" => "dubai",
33 | "state" => "dubai",
34 | "country" => "AE",
35 | "zip" => "54321"
36 | ],
37 | "framed" => true,
38 | "hide_shipping" => true
39 | ];
40 | $page = $plugin->send_api_request($request_url, $data);
41 |
42 | echo "";
43 | exit();
44 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Hosted-payment-page/Create-Payment-Page-HostedPaymentPage.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/request';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "cart_id" => "cart_11111",
11 | "cart_currency" => "EGP",
12 | "cart_amount" => 1000,
13 | "cart_description" => "Description of the items/services",
14 | "paypage_lang" => "en",
15 | "callback" => "https://webhook.site/730acce0-e54e-4522-8a45-f9b8e44624b6", // Nullable - Must be HTTPS, otherwise no post data from paytabs
16 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
17 | "customer_details" => [
18 | "name" => "first last",
19 | "email" => "email@domain.com",
20 | "phone" => "0522222222",
21 | "street1" => "address street",
22 | "city" => "dubai",
23 | "state" => "du",
24 | "country" => "AE",
25 | "zip" => "12345"
26 | ],
27 | "shipping_details" => [
28 | "name" => "name1 last1",
29 | "email" => "email1@domain.com",
30 | "phone" => "971555555555",
31 | "street1" => "street2",
32 | "city" => "dubai",
33 | "state" => "dubai",
34 | "country" => "AE",
35 | "zip" => "54321"
36 | ],
37 | "user_defined" => [
38 | "udf9" => "UDF9 Test9",
39 | "udf3" => "UDF3 Test3"
40 | ]
41 | ];
42 | $page = $plugin->send_api_request($request_url, $data);
43 | header('Location:' . $page['redirect_url']); /* Redirect browser */
44 | exit();
45 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Own-Form - Payment Request/Create-Own-Form - Payment-Request.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/request';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | "cart_id" => "cart_11111",
11 | "cart_currency" => "EGP",
12 | "cart_amount" => 1000,
13 | "cart_description" => "Description of the items/services",
14 | "paypage_lang" => "en",
15 | "callback" => "https://webhook.site/730acce0-e54e-4522-8a45-f9b8e44624b6", // Nullable - Must be HTTPS, otherwise no post data from paytabs
16 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
17 | "customer_details" => [
18 | "name" => "first last",
19 | "email" => "email@domain.com",
20 | "phone" => "0522222222",
21 | "street1" => "address street",
22 | "city" => "dubai",
23 | "state" => "du",
24 | "country" => "AE",
25 | "zip" => "12345"
26 | ],
27 | "shipping_details" => [
28 | "name" => "name1 last1",
29 | "email" => "email1@domain.com",
30 | "phone" => "971555555555",
31 | "street1" => "street2",
32 | "city" => "dubai",
33 | "state" => "dubai",
34 | "country" => "AE",
35 | "zip" => "54321"
36 | ],
37 | "card_details" => [
38 | "pan" => "4000000000000002",
39 | "cvv" => "123",
40 | "expiry_month" => 12,
41 | "expiry_year" => 2022
42 | ]
43 | ];
44 |
45 |
46 | $page = $plugin->send_api_request($request_url, $data);
47 | header('Location:' . $page['redirect_url']); /* Redirect browser */
48 | exit();
49 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Managed-Form - Payment-Request/Send-managed-form.php:
--------------------------------------------------------------------------------
1 | getBaseUrl();
6 | $request_url = 'payment/request';
7 | $data = [
8 | "tran_type" => "sale",
9 | "tran_class" => "ecom",
10 | 'payment_methods' => ['creditcard'],
11 | 'payment_token' => $_POST['token'],
12 | "cart_id" => $_POST['cart_id'],
13 | "cart_currency" => $_POST['currency'],
14 | "cart_amount" => $_POST['amount'],
15 | "cart_description" => "managed form sample",
16 | "paypage_lang" => "en",
17 | "callback" => "https://webhook.site/730acce0-e54e-4522-8a45-f9b8e44624b6", // Nullable - Must be HTTPS, otherwise no post data from paytabs
18 | "return" => $base_url."Result.php", // Must be HTTPS, otherwise no post data from paytabs , must be relative to your site URL
19 | "customer_details" => [
20 | "name" => $_POST['name'],
21 | "email" => $_POST['email'],
22 | "phone" => $_POST['phone'],
23 | "street1" => $_POST['street1'],
24 | "city" => $_POST['city'],
25 | "state" => $_POST['state'],
26 | "country" => $_POST['country'],
27 | "zip" => $_POST['postcode'],
28 | "ip" => file_get_contents("https://api.ipify.org")
29 | ],
30 | "shipping_details" => [
31 | "name" => $_POST['name'],
32 | "email" => $_POST['email'],
33 | "phone" => $_POST['phone'],
34 | "street1" => $_POST['street1'],
35 | "city" => $_POST['city'],
36 | "state" => $_POST['state'],
37 | "country" => $_POST['country'],
38 | "zip" => $_POST['postcode']
39 | ]
40 | ];
41 |
42 | $page = $plugin->send_api_request($request_url, $data);
43 |
44 | if (!empty($page['redirect_url'])) {
45 | header("Location: {$page['redirect_url']}");
46 | exit;
47 | }
48 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Wallet-payments/Samsung-pay.php:
--------------------------------------------------------------------------------
1 | "sale",
8 | "tran_class" => "ecom",
9 | "cart_id" => "cart_11111",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => 1000,
12 | "cart_description" => "Description of the items/services",
13 | "paypage_lang" => "en",
14 | "callback" => "https://webhook.site/ebe60b53-4158-4d82-aa16-231f2823378d",
15 | "return" => "http://localhost/default/checkresponse.php",
16 | "customer_details" => [
17 | "name" => "first last",
18 | "email" => "email@domain.com",
19 | "phone" => "0522222222",
20 | "street1" => "address street",
21 | "city" => "dubai",
22 | "state" => "du",
23 | "country" => "AE",
24 | "zip" => "12345"
25 | ],
26 | "samsung_pay_token" => [ //configuration from your Samsung Developer Account
27 | "3DS" => [
28 | "data" => "eyJhbGciOiJSU0ExXzUiLCJraWQiOiI5ZXlTR0doYTdOd1h5MUZ2ZlR1dU9ZRUt0TjRTNFBYa0xtL2hBOFJDTTBvPSIsInR5cCI6IkpPU0UiLCJjaGFubmVsU2VjdXJpdHlDb250ZXh0IjoiUlNBX1BLSSIsImVuYyI6IkExMjhHQ00ifQ.MavQXDz3LOEiD-I9hyUQE_F_SBSMpwkhp7-MU0SAqMrY77cK7asGqtnySJsm6az7IQp1X4DspSKp3Yn6Dq_1xEaNTtsrEvUri3mL3MX9sOHq3nbJl-M1Wuo25ITSu4kal9Da8Dr-o9U11AhxF8vwfvnosX7D5tR8eNdAzsPi5BdcaB4QQpTFQvWESH48QlTmWmX8HfJLhnin2JH2J0YBiM8yi2h8i_ZOTapeVrjA37ig7VGmf4YnE5CmQZrZBHazYGHr-nzGhIQUyUkYbCvQRUr43k2fYNXbnQb1ARtBXe1jK_e0kxwBQz5TMRaa0RsYJGTlyTsQJrP0T78F3jpMmg.95JMDZbXPv9LFZe3.HuhBARXSZ9RLHEjv4eloQwgNTI9a_kknrrmlXZS1jQljLAj7p3GZVTr3lFhpx0Z3-FXBslVA306yGrj_JcTJjpTwudOE2XVadaSarMpFHiMXHa_fcheqGDS60BeksvHWZmoV51I4WbYLB7tjD_SfAO7Ic0u78OW4BD2AnHEsauWuTwxAZ-g7ma4XRfgO2kWAHuuNdTxY_NtzYLoUix4mH02h6q3ARZ7Za331qGVCLsk90t6-ytJcWpV_._mNeyiwfoSvP84cGzq7PEQ",
29 | "type" => "S",
30 | "version" => "100"
31 | ],
32 | "payment_card_brand" => "VI",
33 | "payment_currency_type" => "USD",
34 | "payment_eco_opt_in" => "false",
35 | "payment_last4_dpan" => "0832",
36 | "payment_last4_fpan" => "9039",
37 | "merchant_ref" => "",
38 | "method" => "3DS",
39 | "recurring_payment" => false,
40 | "payment_shipping_address" => [
41 | "shipping" => [],
42 | "email" => ""
43 | ],
44 | "payment_shipping_method" => ""
45 | ]
46 | ];
47 | $page = $plugin->send_api_request($request_url, $data);
48 | header('Location:' . $page['redirect_url']); /* Redirect browser */
49 | exit();
50 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Paytabs-plugin.php:
--------------------------------------------------------------------------------
1 | $this::BASE_URL . $request_url,
17 | CURLOPT_RETURNTRANSFER => true,
18 | CURLOPT_ENCODING => '',
19 | CURLOPT_MAXREDIRS => 10,
20 | CURLOPT_TIMEOUT => 0,
21 | CURLOPT_CUSTOMREQUEST => isset($request_method) ? $request_method : 'POST',
22 | CURLOPT_POSTFIELDS => json_encode($data, true),
23 | CURLOPT_HTTPHEADER => array(
24 | 'authorization:' . $this::SERVER_KEY,
25 | 'Content-Type:application/json'
26 | ),
27 | ));
28 |
29 | $response = json_decode(curl_exec($curl), true);
30 | curl_close($curl);
31 | return $response;
32 | }
33 |
34 | function getBaseUrl()
35 | {
36 | // output: /myproject/index.php
37 | $currentPath = $_SERVER['PHP_SELF'];
38 |
39 | // output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
40 | $pathInfo = pathinfo($currentPath);
41 |
42 | // output: localhost
43 | $hostName = $_SERVER['HTTP_HOST'];
44 |
45 | // output: http://
46 | $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
47 |
48 | // output: /myproject/sub folder contains PT2/
49 | $current_directory = substr(strrchr($pathInfo['dirname'],'/'), 1);
50 | $parent_directory = substr($pathInfo['dirname'], 0, - strlen($current_directory));
51 |
52 | // return: http://localhost/myproject/
53 | return $protocol.$hostName.$parent_directory;
54 | }
55 |
56 | function is_valid_redirect($post_values)
57 | {
58 | $serverKey = $this::SERVER_KEY;
59 |
60 | // Request body include a signature post Form URL encoded field
61 | // 'signature' (hexadecimal encoding for hmac of sorted post form fields)
62 | $requestSignature = $post_values["signature"];
63 | unset($post_values["signature"]);
64 | $fields = array_filter($post_values);
65 |
66 | // Sort form fields
67 | ksort($fields);
68 |
69 | // Generate URL-encoded query string of Post fields except signature field.
70 | $query = http_build_query($fields);
71 |
72 | $signature = hash_hmac('sha256', $query, $serverKey);
73 | if (hash_equals($signature, $requestSignature) === TRUE) {
74 | // VALID Redirect
75 | return true;
76 | } else {
77 | // INVALID Redirect
78 | return false;
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Managed-Form - Payment-Request/Create-managed-Form-Payment-Request.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Managed Form
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
85 |
86 |
87 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/PHP-sample-code-PT2/Wallet-payments/Apple-pay.php:
--------------------------------------------------------------------------------
1 | "sale",
8 | "tran_class" => "ecom",
9 | "cart_id" => "cart_11111",
10 | "cart_currency" => "EGP",
11 | "cart_amount" => 1000,
12 | "cart_description" => "Description of the items/services",
13 | "paypage_lang" => "en",
14 | "callback" => "https://webhook.site/ebe60b53-4158-4d82-aa16-231f2823378d",
15 | "return" => "http://localhost/default/checkresponse.php",
16 | "customer_details" => [
17 | "name" => "first last",
18 | "email" => "email@domain.com",
19 | "phone" => "0522222222",
20 | "street1" => "address street",
21 | "city" => "dubai",
22 | "state" => "du",
23 | "country" => "AE",
24 | "zip" => "12345"
25 | ],
26 | "apple_pay_token" => [ //configuration from your Apple Developer Account
27 | "paymentMethod" => [
28 | "network" => "Visa",
29 | "type" => "Debit",
30 | "displayName" => "Visa 4228"
31 | ],
32 | "transactionIdentifier" => "D32A2C43FCC4314A668FFDB95B0F38D0BEF0B2F6AC8569CC433607BA51D25301",
33 | "paymentData" => [
34 | "data" => "P\/l0iLnWAj393LZyMjdblyJHo8zUrAv2i73tcSnFkLDCFkuk35oh5+CCA7G6rBFXD0O6iu3kS3cE+yW3uhS88vI7jqMMG4bnJ0GdJUckJ6P7o++IurHG0bIHhOlu8gqL\/1Bd73sHAKp4eK8GRQ0muRQGPwpTUf82J6mvntA\/QhQ3b4Bd2ycn0N5T31XA8okVdNi++8TBuFgflz+61ar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"header" => [
37 | "publicKeyHash" => "dQ1T3uh4uMRK7OAynypjLF7V9NWdL49JVKIHU+jDsww=",
38 | "ephemeralPublicKey" => "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEcPy\/H\/285E6ruf9Y4Yn3D41MdtLFRqdGVPoXr6wWpWk\/cBr31AZSVWCorIu4HT92GNy5efMcinrAyev2Mwy+zg==",
39 | "transactionId" => "d32a2c43fcc4314a668ffdb95b0f38d0bef0b2f6ac8569cc433607ba51d25301"
40 | ],
41 | "version" => "EC_v1"
42 | ]
43 | ]
44 | ];
45 | $page = $plugin->send_api_request($request_url, $data);
46 | header('Location:' . $page['redirect_url']); /* Redirect browser */
47 | exit();
48 |
--------------------------------------------------------------------------------