这是我的 ChargifyCoupon.php
public function create($product_family_id = null, $details = []) {
$details = array_replace_recursive([
"name" => "15% off",
"code" => "15OFF",
"description" => "15% off for life",
"percentage" => "15",
"allow_negative_balance" => "false",
"recurring" => "false",
"end_date" => "2016-12-31T23:59:59-04:00",
"product_family_id" => $product_family_id
], $details);
$returnData = $this->connector->createCoupon($details, 'JSON');
var_dump($returnData);
die;
}
这是我的 ChargifyConnector.php
function createCoupon($product_family_id, $coupon_details = [], $format = 'XML') {
$extension = strtoupper($format) == 'XML' ? '.xml' : '.json';
$base_url = "/product_families/{$product_family_id}/coupons" . $extension;
$data = json_encode([
"coupon" => $coupon_details
]);
$coupon = $this->sendRequest($base_url, $format, 'POST', $data);
if ($coupon->code == 200) {
return $coupon->response;
} elseif ($coupon->code == 404 || $coupon->code == 500) {
var_dump($coupon);
die;
throw new \Exception($coupon->code, "Coupon was not created.");
}
}
当我试图查看结果时,我得到“数组到字符串的转换”