· 5 years ago · Feb 15, 2020, 04:20 PM
1$date = gmdate("Y-m-d H:i:s", time());
2//YYYY-MM-DD HH:MM:SS
3
4$sellerId = '901419714';
5$secretKey = 'F574E613-38C8-46C6-8953-FD497EC7DD87';
6
7//HASH: The hashmac digest with an md5 hashing algorithm of the following:
8// LEN(VENDOR_CODE) + VENDOR_CODE + LEN(REQUEST_DATE_TIME) + REQUEST_DATE_TIME.
9// Use the secret key associated with your account for the hashing.
10$input = (strlen($sellerId) . $sellerId . strlen($date) . $date);
11
12echo $input;
13$hash = hash_hmac('md5', $input, $secretKey);
14$authHeader = 'X-Avangate-Authentication: code="'.$sellerId.'" date="'.$date.'" hash="'.$hash.'"';
15
16echo $authHeader;
17
18
19$ch = curl_init();
20
21curl_setopt($ch, CURLOPT_URL, "https://api.2checkout.com/rest/5.0/orders/");
22curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
23curl_setopt($ch, CURLOPT_HEADER, FALSE);
24
25curl_setopt($ch, CURLOPT_POST, TRUE);
26
27curl_setopt($ch, CURLOPT_POSTFIELDS, "{
28 \"Currency\": \"usd\",
29 \"Language\": \"en\",
30 \"Country\": \"us\",
31 \"CustomerIP\": \"91.220.121.21\",
32 \"Source\": \"testAPI.com\",
33 \"ExternalReference\": \"REST_API_AVANGTE\",
34 \"Items\": [
35 {
36 \"Code\": null,
37 \"Quantity\": \"1\",
38 \"IsDynamic\": true,
39 \"Tangible\": false,
40 \"PurchaseType\": \"PRODUCT\",
41 \"Price\": {
42 \"Amount\": \"100\",
43 \"Type\": \"CUSTOM\"
44 },
45 \"Name\": \"Dynamic product\",
46 \"Description\": \"Test description\",
47 \"PriceOptions\": [
48 {
49 \"Name\": \"Price option 1\",
50 \"Value\": \"Price option value 1\",
51 \"Surcharge\": \"100\"
52 }
53 ],
54 \"RecurringOptions\": {
55 \"CycleLength\": 1,
56 \"CycleUnit\": \"MONTH\",
57 \"CycleAmount\": 444,
58 \"ContractLength\": 4,
59 \"ContractUnit\": \"YEAR\"
60 }
61 },
62 {
63 \"IsDynamic\": true,
64 \"Quantity\": \"1\",
65 \"PurchaseType\": \"SHIPPING\",
66 \"Price\": {
67 \"Amount\": \"20\"
68 },
69 \"Name\": \"Shipping item\"
70 },
71 {
72 \"IsDynamic\": true,
73 \"Quantity\": \"1\",
74 \"PurchaseType\": \"TAX\",
75 \"Price\": {
76 \"Amount\": \"10\"
77 },
78 \"Name\": \"Tax item\",
79 \"RecurringOptions\": {
80 \"CycleLength\": 1,
81 \"CycleUnit\": \"MONTH\",
82 \"CycleAmount\": 12,
83 \"ContractLength\": 4,
84 \"ContractUnit\": \"YEAR\"
85 }
86 },
87 {
88 \"IsDynamic\": true,
89 \"Quantity\": \"1\",
90 \"PurchaseType\": \"COUPON\",
91 \"Price\": {
92 \"Amount\": \"50\"
93 },
94 \"Name\": \"Discount item\"
95 }
96 ],
97 \"BillingDetails\": {
98 \"Address1\": \"Test Address\",
99 \"City\": \"LA\",
100 \"State\": \"California\",
101 \"CountryCode\": \"US\",
102 \"Email\": \"testcustomer@2Checkout.com\",
103 \"FirstName\": \"Customer\",
104 \"LastName\": \"2Checkout\",
105 \"Zip\": \"12345\"
106 },
107 \"PaymentDetails\": {
108 \"Type\": \"CC\",
109 \"Currency\": \"USD\",
110 \"CustomerIP\": \"91.220.121.21\",
111 \"PaymentMethod\": {
112 \"CardNumber\": \"4111111111111111\",
113 \"CardType\": \"VISA\",
114 \"ExpirationYear\": \"2018\",
115 \"ExpirationMonth\": \"12\",
116 \"CCID\": \"123\",
117 \"HolderName\": \"John Doe\",
118 \"RecurringEnabled\": true,
119 \"HolderNameTime\": \"12\",
120 \"CardNumberTime\": \"12\",
121 \"Vendor3DSReturnURL\": \"http://myreturnurl.com\",
122 \"Vendor3DSCancelURL\": \"http://cancelurl.com\"
123 }
124 }
125}");
126
127curl_setopt($ch, CURLOPT_HTTPHEADER, array(
128 $authHeader,
129 "Content-Type: application/json",
130 "Accept: application/json",
131));
132
133$response = curl_exec($ch);
134curl_close($ch);
135
136var_dump($response);