286 lines
12 KiB
PHP
Executable File

<?php
require_once ('fixed/config/go_con.php');
// Payment Types
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'https://api.tamara.co/checkout/payment-types?country=SA');
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
// $headers = array();
// $headers[] = 'Accept: application/json';
// $headers[] = 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiI2YmUyNzdlMC0wNGY5LTRmYjUtOGNhYi05NTMwYzJhN2U1YzMiLCJ0eXBlIjoibWVyY2hhbnQiLCJzYWx0IjoiZWM3YmJhN2E3M2VkYzE2NjAzMmMyZjAyMGI4MzQ4MjEiLCJyb2xlcyI6WyJST0xFX01FUkNIQU5UIl0sImlhdCI6MTcxNDMwMzMxMSwiaXNzIjoiVGFtYXJhIFBQIn0.VG9AJfPwLhQUDySxGdBuC05Kdf4-1TiP1I-l8sgYQCPWKSMI4t6-5XZ3injQ3utncYClIcJ8hUex7N2yWabxo4qsQCNLu0uRb3kcqwSxxFsP2RKsInxCobzf8YCFXFJo6X5Ho4z0ffDlXIaepOpUKFn5s_usiEGSEf6Agy8S94Gbcwj0NmhVV7Sxb8hwM7GNaADhH2-Wu9NmVpBe9JxD57718C9e8EZm9vHNo-_4LxB90Hqf2ACziW6c6-6t7e17dDtthXwS_24lVVEhUL5K2ZcLLWt-2hfsx3UuNe4tA2dtcCkZhgMW2aJZUOfJO_4qdBmzX401YXDprPRXKbUYkw';
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// $result = curl_exec($ch);
// if (curl_errno($ch)) {
// echo 'Error:' . curl_error($ch);
// }
// curl_close($ch);
// Payment Types
// Check Payment Options Availability
// $ch = curl_init();
// $CURLOPT_POSTFIELDS = [ // required
// "country" => "SA",
// "phone_number" => "509033601",
// "order_value" => [
// "amount" => 100,
// "currency" => "SAR"
// ],
// "is_vip" => false
// ];
// curl_setopt($ch, CURLOPT_URL, 'https://api.tamara.co/checkout/payment-options-pre-check');
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $CURLOPT_POSTFIELDS);
// $headers = array();
// $headers[] = 'Accept: application/json';
// $headers[] = 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiI2YmUyNzdlMC0wNGY5LTRmYjUtOGNhYi05NTMwYzJhN2U1YzMiLCJ0eXBlIjoibWVyY2hhbnQiLCJzYWx0IjoiZWM3YmJhN2E3M2VkYzE2NjAzMmMyZjAyMGI4MzQ4MjEiLCJyb2xlcyI6WyJST0xFX01FUkNIQU5UIl0sImlhdCI6MTcxNDMwMzMxMSwiaXNzIjoiVGFtYXJhIFBQIn0.VG9AJfPwLhQUDySxGdBuC05Kdf4-1TiP1I-l8sgYQCPWKSMI4t6-5XZ3injQ3utncYClIcJ8hUex7N2yWabxo4qsQCNLu0uRb3kcqwSxxFsP2RKsInxCobzf8YCFXFJo6X5Ho4z0ffDlXIaepOpUKFn5s_usiEGSEf6Agy8S94Gbcwj0NmhVV7Sxb8hwM7GNaADhH2-Wu9NmVpBe9JxD57718C9e8EZm9vHNo-_4LxB90Hqf2ACziW6c6-6t7e17dDtthXwS_24lVVEhUL5K2ZcLLWt-2hfsx3UuNe4tA2dtcCkZhgMW2aJZUOfJO_4qdBmzX401YXDprPRXKbUYkw';
// $headers[] = 'Content-Type: application/json';
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// $result = curl_exec($ch);
// if (curl_errno($ch)) {
// echo 'Error:' . curl_error($ch);
// }
// curl_close($ch);
// Check Payment Options Availability
// Create Checkout Session
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'https://api.tamara.co/checkout');
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_POST, 1);
// $CURLOPT_POSTFIELDS = [
// "total_amount" => [ // required
// "amount" => 300,
// "currency" => "SAR"
// ],
// "shipping_amount" => [ // required
// "amount" => 1,
// "currency" => "SAR"
// ],
// "tax_amount" => [ // required
// "amount" => 1,
// "currency" => "SAR"
// ],
// "order_reference_id" => "abd12331-a123-1234-4567-fbde34ae", // required
// "order_number" => "A123125",
// "discount" => [ // required
// "name" => "Voucher A",
// "amount" => [
// "amount" => 0,
// "currency" => "SAR"
// ]
// ],
// "items" => [
// [
// "name" => "Lego City 8601", // required
// "type" => "Digital", // required
// "reference_id" => "123", // required
// "sku" => "SA-12436", // required
// "quantity" => 1, // required
// "discount_amount" => [
// "amount" => 100,
// "currency" => "SAR"
// ],
// "tax_amount" => [
// "amount" => 10,
// "currency" => "SAR"
// ],
// "unit_price" => [
// "amount" => 490,
// "currency" => "SAR"
// ],
// "total_amount" => [ // required
// "amount" => 100,
// "currency" => "SAR"
// ]
// ]
// ],
// "consumer" => [ // required
// "email" => "customer@email.com",
// "first_name" => "Mona",
// "last_name" => "Lisa",
// "phone_number" => "509033601"
// ],
// "country_code" => "SA", // required
// "description" => "Enter order description here.", // required
// "merchant_url" => [ // required
// "cancel" => "http://example.com/#/cancel",
// "failure" => "http://example.com/#/fail",
// "success" => "http://example.com/#/success",
// "notification" => "https://example-notification.com/payments/tamaranotifications"
// ],
// "payment_type" => "PAY_BY_INSTALMENTS",
// "instalments" => 3,
// "billing_address" => [
// "city" => "Riyadh",
// "country_code" => "SA",
// "first_name" => "Mona",
// "last_name" => "Lisa",
// "line1" => "3764 Al Urubah Rd",
// "line2" => "string",
// "phone_number" => "532298658",
// "region" => "As Sulimaniyah"
// ],
// "shipping_address" => [
// "city" => "Riyadh",
// "country_code" => "SA",
// "first_name" => "Mona",
// "last_name" => "Lisa",
// "line1" => "3764 Al Urubah Rd",
// "line2" => "string",
// "phone_number" => "532298658",
// "region" => "As Sulimaniyah"
// ],
// "platform" => "platform name here",
// "is_mobile" => false,
// "locale" => "ar_SA",
// "risk_assessment" => [ // required
// "customer_age" => 21,
// "customer_dob" => "01-12-2000",
// "customer_gender" => "Female",
// "customer_nationality" => "SA",
// "is_premium_customer" => false,
// "is_existing_customer" => false,
// "is_guest_user" => false,
// "account_creation_date" => "12-06-2020",
// "platform_account_creation_date" => "12-06-2020",
// "date_of_first_transaction" => "12-06-2020",
// "is_card_on_file" => false,
// "is_COD_customer" => false,
// "has_delivered_order" => true,
// "is_phone_verified" => false,
// "is_fraudulent_customer" => false,
// "total_ltv" => 200,
// "total_order_count" => 15,
// "order_amount_last3months" => 2000,
// "order_count_last3months" => 10,
// "last_order_date" => "12-06-2020",
// "last_order_amount" => 2000,
// "reward_program_enrolled" => false,
// "reward_program_points" => 2000
// ],
// "additional_data" => [
// "delivery_method" => "Home Delivery",
// "pickup_store" => "Store A",
// "store_code" => "Branch A",
// "vendor_amount" => 0,
// "merchant_settlement_amount" => 0,
// "vendor_reference_code" => "AZ1234"
// ]
// ];
// $CURLOPT_POSTFIELDS = json_encode($CURLOPT_POSTFIELDS, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $CURLOPT_POSTFIELDS);
// $headers = array();
// $headers[] = 'Accept: application/json';
// $headers[] = 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiI2YmUyNzdlMC0wNGY5LTRmYjUtOGNhYi05NTMwYzJhN2U1YzMiLCJ0eXBlIjoibWVyY2hhbnQiLCJzYWx0IjoiZWM3YmJhN2E3M2VkYzE2NjAzMmMyZjAyMGI4MzQ4MjEiLCJyb2xlcyI6WyJST0xFX01FUkNIQU5UIl0sImlhdCI6MTcxNDMwMzMxMSwiaXNzIjoiVGFtYXJhIFBQIn0.VG9AJfPwLhQUDySxGdBuC05Kdf4-1TiP1I-l8sgYQCPWKSMI4t6-5XZ3injQ3utncYClIcJ8hUex7N2yWabxo4qsQCNLu0uRb3kcqwSxxFsP2RKsInxCobzf8YCFXFJo6X5Ho4z0ffDlXIaepOpUKFn5s_usiEGSEf6Agy8S94Gbcwj0NmhVV7Sxb8hwM7GNaADhH2-Wu9NmVpBe9JxD57718C9e8EZm9vHNo-_4LxB90Hqf2ACziW6c6-6t7e17dDtthXwS_24lVVEhUL5K2ZcLLWt-2hfsx3UuNe4tA2dtcCkZhgMW2aJZUOfJO_4qdBmzX401YXDprPRXKbUYkw';
// $headers[] = 'Content-Type: application/json';
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// $result = curl_exec($ch);
// if (curl_errno($ch)) {
// echo 'Error:' . curl_error($ch);
// }
// curl_close($ch);
// Create Checkout Session
// Authorise Order
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'https://api.tamara.co/orders/ff776045-513b-4cd7-8b4f-e60673daad84/authorise');
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_POST, 1);
// $headers = array();
// $headers[] = 'Accept: application/json';
// $headers[] = 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiI2YmUyNzdlMC0wNGY5LTRmYjUtOGNhYi05NTMwYzJhN2U1YzMiLCJ0eXBlIjoibWVyY2hhbnQiLCJzYWx0IjoiZWM3YmJhN2E3M2VkYzE2NjAzMmMyZjAyMGI4MzQ4MjEiLCJyb2xlcyI6WyJST0xFX01FUkNIQU5UIl0sImlhdCI6MTcxNDMwMzMxMSwiaXNzIjoiVGFtYXJhIFBQIn0.VG9AJfPwLhQUDySxGdBuC05Kdf4-1TiP1I-l8sgYQCPWKSMI4t6-5XZ3injQ3utncYClIcJ8hUex7N2yWabxo4qsQCNLu0uRb3kcqwSxxFsP2RKsInxCobzf8YCFXFJo6X5Ho4z0ffDlXIaepOpUKFn5s_usiEGSEf6Agy8S94Gbcwj0NmhVV7Sxb8hwM7GNaADhH2-Wu9NmVpBe9JxD57718C9e8EZm9vHNo-_4LxB90Hqf2ACziW6c6-6t7e17dDtthXwS_24lVVEhUL5K2ZcLLWt-2hfsx3UuNe4tA2dtcCkZhgMW2aJZUOfJO_4qdBmzX401YXDprPRXKbUYkw';
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// $result = curl_exec($ch);
// if (curl_errno($ch)) {
// echo 'Error:' . curl_error($ch);
// }
// curl_close($ch);
// Authorise Order
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-sandbox.tamara.co/checkout/in-store-session');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$CURLOPT_POSTFIELDS = [
"total_amount" => [
"amount" => 300,
"currency" => "SAR"
],
"phone_number" => "509033601",
"email" => "customer@emailhere.com",
"order_reference_id" => "6be277e0-04f9-4fb5-8cab-9530c2a7e5c3",
"order_number" => "A1231234123",
"items" => [
[
"name" => "Lego City 8601",
"type" => "Digital",
"reference_id" => "123",
"sku" => "SA-12436",
"quantity" => 1,
"discount_amount" => [
"amount" => 100,
"currency" => "SAR"
],
"tax_amount" => [
"amount" => 10,
"currency" => "SAR"
],
"unit_price" => [
"amount" => 490,
"currency" => "SAR"
],
"total_amount" => [
"amount" => 100,
"currency" => "SAR"
]
]
],
"locale" => "ar_SA",
"payment_type" => "PAY_BY_INSTALMENTS",
"additional_data" => [
"store_code" => "exit 7"
]
];
$CURLOPT_POSTFIELDS = json_encode($CURLOPT_POSTFIELDS, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $CURLOPT_POSTFIELDS);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiJiYWFjZjEyMS03MjRmLTRlN2EtYjNmNy1lMDc1OTYwZTRjMDYiLCJ0eXBlIjoibWVyY2hhbnQiLCJzYWx0IjoiNTdhNTU0ODA4NjgwZjQwZGRiYmY3NDk3NzY3MjFjZjQiLCJyb2xlcyI6WyJST0xFX01FUkNIQU5UIl0sImlhdCI6MTcxNDM4MjYyMiwiaXNzIjoiVGFtYXJhIn0.P6mb0dU3CR3gC_l7KuOWk5S-joelzzUqzXaAP-jyoGAgmt1j2NNHPgQDj3DJF7gVIJNvTNigkbu25ft2pZvCFQrJMzDup42YAFxEVd80b4NnPREx3pA0okkpjq-CyRfVNbcV31JZx2LNOVXQToQFrm8_J6lkosvMPBLqsM5M9szXxcm5Gb-e-WcBWfqtwLwBIVOK__E9nzAaZUECVdM8Aeb0WYY0xa0lcYf0dVSJktFGTPKK_-cIgnvMV0EunEULNtJySMarlVyYF-I3EbI4moL3rZhM9_jxMdn0uApClAiT6T9UlVCwcgTqZFJ4fm8rVPa2BDGSpbPWwqk2xTAOCw';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
var_dump(json_decode($result, true, 512, JSON_UNESCAPED_UNICODE));