-
Notifications
You must be signed in to change notification settings - Fork 52
/
PartialAuthorization.php
105 lines (89 loc) · 3.78 KB
/
PartialAuthorization.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . '../../../vendor/autoload.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . '../../../Resources/ExternalConfiguration.php';
function PartialAuthorization()
{
$clientReferenceInformationArr = [
"code" => "1234567890"
];
$clientReferenceInformation = new CyberSource\Model\Ptsv2paymentsClientReferenceInformation($clientReferenceInformationArr);
$paymentInformationCardArr = [
"number" => "4111111111111111",
"expirationMonth" => "12",
"expirationYear" => "2031",
"securityCode" => "123"
];
$paymentInformationCard = new CyberSource\Model\Ptsv2paymentsPaymentInformationCard($paymentInformationCardArr);
$paymentInformationArr = [
"card" => $paymentInformationCard
];
$paymentInformation = new CyberSource\Model\Ptsv2paymentsPaymentInformation($paymentInformationArr);
$orderInformationAmountDetailsArr = [
"totalAmount" => "7012.00",
"currency" => "USD"
];
$orderInformationAmountDetails = new CyberSource\Model\Ptsv2paymentsOrderInformationAmountDetails($orderInformationAmountDetailsArr);
$orderInformationBillToArr = [
"firstName" => "John",
"lastName" => "Doe",
"address1" => "1 Market St",
"locality" => "san francisco",
"administrativeArea" => "CA",
"postalCode" => "94105",
"country" => "US",
"email" => "test@cybs.com",
"phoneNumber" => "4158880000"
];
$orderInformationBillTo = new CyberSource\Model\Ptsv2paymentsOrderInformationBillTo($orderInformationBillToArr);
$orderInformationArr = [
"amountDetails" => $orderInformationAmountDetails,
"billTo" => $orderInformationBillTo
];
$orderInformation = new CyberSource\Model\Ptsv2paymentsOrderInformation($orderInformationArr);
$pointOfSaleInformationEmvArr = [
"fallback" => false,
"fallbackCondition" => 1
];
$pointOfSaleInformationEmv = new CyberSource\Model\Ptsv2paymentsPointOfSaleInformationEmv($pointOfSaleInformationEmvArr);
$pointOfSaleInformationArr = [
"catLevel" => 6,
"terminalCapability" => 4,
"emv" => $pointOfSaleInformationEmv
];
$pointOfSaleInformation = new CyberSource\Model\Ptsv2paymentsPointOfSaleInformation($pointOfSaleInformationArr);
$requestObjArr = [
"clientReferenceInformation" => $clientReferenceInformation,
"paymentInformation" => $paymentInformation,
"orderInformation" => $orderInformation,
"pointOfSaleInformation" => $pointOfSaleInformation
];
$requestObj = new CyberSource\Model\CreatePaymentRequest($requestObjArr);
$commonElement = new CyberSource\ExternalConfiguration();
$config = $commonElement->ConnectionHost();
$merchantConfig = $commonElement->merchantConfigObject();
$api_client = new CyberSource\ApiClient($config, $merchantConfig);
$api_instance = new CyberSource\Api\PaymentsApi($api_client);
try {
$apiResponse = $api_instance->createPayment($requestObj);
print_r(PHP_EOL);
print_r($apiResponse);
WriteLogAudit($apiResponse[1]);
return $apiResponse;
} catch (Cybersource\ApiException $e) {
print_r($e->getResponseBody());
print_r($e->getMessage());
$errorCode = $e->getCode();
WriteLogAudit($errorCode);
}
}
if (!function_exists('WriteLogAudit')){
function WriteLogAudit($status){
$sampleCode = basename(__FILE__, '.php');
print_r("\n[Sample Code Testing] [$sampleCode] $status");
}
}
if(!defined('DO_NOT_RUN_SAMPLES')){
echo "\nPartialAuthorization Sample Code is Running..." . PHP_EOL;
PartialAuthorization();
}
?>