· 5 years ago · Feb 16, 2020, 12:18 AM
1$date = gmdate("Y-m-d H:i:s", time());
2//YYYY-MM-DD HH:MM:SS
3
4$sellerId = '250282309866';
5$secretKey = 'UNX49o5n+(Ey^IQ=0ds*';
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
12//echo $input;
13$hash = hash_hmac('md5', $input, $secretKey);
14$authHeader = 'X-Avangate-Authentication: code="'.$sellerId.'" date="'.$date.'" hash="'.$hash.'"';
15
16//echo $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 \"RecurringOptions\": {
48 \"CycleLength\": 1,
49 \"CycleUnit\": \"MONTH\",
50 \"CycleAmount\": 444,
51 \"ContractLength\": 4,
52 \"ContractUnit\": \"YEAR\"
53 }
54 }
55 ],
56 \"BillingDetails\": {
57 \"Address1\": \"Test Address\",
58 \"City\": \"LA\",
59 \"State\": \"California\",
60 \"CountryCode\": \"US\",
61 \"Email\": \"testcustomer@2Checkout.com\",
62 \"FirstName\": \"Customer\",
63 \"LastName\": \"2Checkout\",
64 \"Zip\": \"12345\"
65 },
66 \"PaymentDetails\": \"TEST\"
67}");
68
69curl_setopt($ch, CURLOPT_HTTPHEADER, array(
70 $authHeader,
71 "Content-Type: application/json",
72 "Accept: application/json",
73));
74
75$response = curl_exec($ch);
76curl_close($ch);
77
78var_dump($response);