Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
1
Indexable
Never
try {
    $customer_id = $data['customer_id'];
    $access_token = $this->getZohoToken();
    $organizationid = config('app.organization_id');

    $price = $data['price'];
    $plan_code = $data['plan_code'];
    $billing_cycles = $data['billing_cycles'];
    $plan_description = $data['plan_description'];
    $coupon_code = $data['coupon_code']; // Replace this with the actual coupon code you want to apply

    $headers = array();
    $headers[] = 'Content-Type: application/json;charset=UTF-8';
    $headers[] = 'Authorization: Zoho-oauthtoken '.$access_token;
    $headers[] = 'X-com-zoho-subscriptions-organizationid: '.$organizationid;
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, config('app.ZOHO_SUBSCRIPTION_URL').'subscriptions');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS,"{
            \"customer_id\": \"$customer_id\",
            \"plan\": {
                \"plan_code\": \"$plan_code\",
                \"plan_description\": \"$plan_description\",
                \"quantity\": \"1\",
                \"price\": \"$price\",
                \"billing_cycles\": \"$billing_cycles\",
                \"trial_days\": 0,
                \"setup_fee\": \"0.00\",
                \"tax_id\": \"\",
                \"setup_fee_tax_id\": \"\"
            },
            \"coupon_code\": \"$coupon_code\", // Add the coupon code here
            \"auto_collect\": false
        }"
    );

    $result = curl_exec($ch);
    curl_close($ch);
    $response = json_decode($result);

    \Log::info("zohoSubscription  response ==> ", [$response]);
} catch (\Throwable $th) {
    \Log::info("zohoSubscription  Throwable ==> ", [$th->getMessage()]);
}