我正在尝试将 php 与 2checkout api 集成,以便为用户创建新订阅。在2checkout 文档中,他们提供了一个根据请求发送的 JSON 正文:-
$payload = '{
"AdditionalInfo": null,
"CustomPriceBillingCyclesLeft": 2,
"DeliveryInfo": {
"Codes": [
{
"Code": "___TEST___CODE____",
"Description": null,
"ExtraInfo": null,
"File": null
}
],
"Description": null
},
"EndUser": {
"Address1": "Test Address",
"Address2": "",
"City": "LA",
"Company": "",
"CountryCode": "us",
"Email": "customer@2Checkout.com",
"Fax": "",
"FirstName": "Customer",
"Language": "en",
"LastName": "2Checkout",
"Phone": "",
"State": "CA",
"Zip": "12345"
},
"ExpirationDate": "2020-06-27",
"ExternalCustomerReference": null,
"ExternalSubscriptionReference": "ThisIsYourUniqueIdentifier123",
"NextRenewalPrice": 19.99,
"NextRenewalPriceCurrency": "usd",
"PartnerCode": "",
"Payment": {
"CCID": "123",
"CardNumber": "4111111111111111",
"CardType": "VISA",
"ExpirationMonth": "12",
"ExpirationYear": "2018",
"HolderName": "John Doe"
},
"Product": {
"ProductCode": "nfbox-1m",
"ProductId": "29810789",
"ProductName": "1 Month NFBOX - Platinum Membership - عضوية البلاتينوم ",
"ProductQuantity": 1,
"ProductVersion": ""
},
"StartDate": "2020-05-27",
"SubscriptionValue": 19.99,
"SubscriptionValueCurrency": "usd",
"Test": 1
}';
当我返回测试时:
return json_encode($payload)
我正在使用 Guzzlehttp 向 2checkout 发布请求:-
$client = new GuzzleHttp\Client(['base_uri' => 'https://api.avangate.com/rest/6.0/']);
$r = $client->request('POST', 'orders/', [
'headers' => [
'X-Avangate-Authentication' => $header,
'Content-Type' => 'application/json',
'Accept' => 'application/json'
], 'json' => json_encode($payload)
]);
$response = $r->getBody();
return json_decode($response);
我如何在上述请求中包含 json 正文?
慕无忌1623718