#devsmith

1 messages · Page 1 of 1 (latest)

turbid zenithBOT
feral jay
#

You can look at the price you passed price_1NzuVeJJ1tZuYKoiQwNsAZjP

#

Paste it to your Dashboard search bar

wooden gust
#

let me check

#

its showing like this
Pricing
Usage type Recurring usage
Currency USD
Interval Every 2 months
Price per unit $815.85
Tax behavior Unspecified
Default price No

feral jay
#

So it's every 2 months

wooden gust
#

you mean this amount will be deduct every two months ?

feral jay
#

Yep

wooden gust
#

but i wanted to pass this amount as subscription for two months like $815.85 this month as soon as subscription starts and next would be in next month and when two months over subscription gets cancelled automaticcally

#

here is my code and api which im using

$curl = curl_init();

            $data = array(
                'unit_amount_decimal' => ($newPrice * 100),
                'currency' => 'usd',
                'recurring' => ['interval' => 'month', 'interval_count' => $interval], // Add interval_count here
                'product' => $productId,
            );

            curl_setopt_array($curl, array(
                CURLOPT_URL => 'https://api.stripe.com/v1/prices',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS => http_build_query($data), // Convert data array to query string
                CURLOPT_HTTPHEADER => array(
                    'Content-Type: application/x-www-form-urlencoded',
                    'Authorization: Bearer ' . $stripe['secret'],
                ),
            ));
feral jay
#

two months like $815.85 this month as soon as subscription starts and next would be in next month and when two months over subscription gets cancelled automaticcally
Sounds like you want a monthly price of $815.85, and schedule the Sub to cancel after 2 months

#

Let's do it separately, just set the price to 81585, interval = month, interval_count = 1

#

Then you set Subscription cancel_at to an Unix timestamp of 2 months later

wooden gust
#

how i set up here $data = array(
'unit_amount_decimal' => ($newPrice * 100),
'currency' => 'usd',
'recurring' => ['interval' => 'month', 'interval_count' => $interval], // Add interval_count here
'product' => $productId,
);

feral jay
#

interval_count = 1

#

And that's only for creating the Price

wooden gust
#

yes that would be for monthly i understand it i will pass interval 1 value so it will become monthly

#

but what about third parameter in whcih i want it to cancel after two months

feral jay
#

You want to pass it in the Create Subscription API later

wooden gust
#

$subscriptionData = [
'customer' => $customerId,
'items' => [['price' => $priceId]],
];

                curl_setopt_array($curl, array(
                    CURLOPT_URL => 'https://api.stripe.com/v1/subscriptions',
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => '',
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => 'POST',
                    CURLOPT_POSTFIELDS => http_build_query($subscriptionData), // Convert the data to a query string
                    CURLOPT_HTTPHEADER => array(
                        'Content-Type: application/x-www-form-urlencoded',
                        'Authorization: Bearer ' . $stripe['secret'],
                    ),
                ));

                $subscriptionResponse = curl_exec($curl);
#

check above curl code please and tell me which parameter i should pass and also what would be it data type with example

#

like in here
$subscriptionData = [
'customer' => $customerId,
'items' => [['price' => $priceId]],
];

feral jay
#

cancel_at

#

You need to calculate an Unix timestamp of 2 monthts later, and pass into cancel_at