Stripe API subscriptions with plan coupon and discounts using PHP

Stripe API subscriptions with plan coupon and discounts using PHP

In this Post We Will Explain About is Stripe API subscriptions with plan coupon and discounts using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to php – Stripe create customer with coupon at subscription levelExample

In this post we will show you Best way to implement Create a Subscription Service with Stripe and PHP, hear for Stripe API subscriptions with plans and copanswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Stripe API subscriptions using Curl Functions

1)Use Stripe to build subscription plans and handle payments In this URL : https://stripe.com/docs

	// PHP functions to curl call
    function call () {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->parameters));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $output = curl_exec($ch);
        curl_close($ch);

        return json_decode($output, true); // return here php array with stripe api response
    }

Full Example Of stripe subscriptions coupon code example

headers = array('Authorization: Bearer sk_test_jSDjhSS58EDkh6mEaJH5d1fp'); // HERE STRIPE_API_KEY = your application stripe api key
    }

	// PHP functions to curl call
    function call () {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->parameters));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $output = curl_exec($ch);
        curl_close($ch);

        return json_decode($output, true); // return here php array with stripe api response
    }
}

$subscription = new Stripe();
$subscription->url .= 'customers';
$subscription->parameters['email'] = '[email protected]';
$customer = $subscription->call();

// create simple customer subscription with your credit card and simple plan
$subscription = new Stripe();
$subscription->url .= 'customers/'.$customer['id'].'/subscriptions';
$subscription->parameters['plan'] = 'deluxe'; // name of the simple stripe plan i.e. my_stripe_plan
$subscription->parameters['coupon'] = 'free-period'; 
$subscription->parameters['trial_end'] = '1500374577';


$subscription_add = $subscription->call();
echo "<pre>";
print_r($subscription_add);
echo "</pre>";

?>

Response OutPut

Array
(
    [id] => sub_B0NaTziRwmZEtW
    [object] => subscription
    [application_fee_percent] => 
    [cancel_at_period_end] => 
    [canceled_at] => 
    [created] => 1499773624
    [current_period_end] => 1500374577
    [current_period_start] => 1499773624
    [customer] => cus_B0NaauYAdsB4KG
    [discount] => Array
        (
            [object] => discount
            [coupon] => Array
                (
                    [id] => free-period
                    [object] => coupon
                    [amount_off] => 
                    [created] => 1499757121
                    [currency] => 
                    [duration] => once
                    [duration_in_months] => 
                    [livemode] => 
                    [max_redemptions] => 
                    [metadata] => Array
                        (
                        )

                    [percent_off] => 100
                    [redeem_by] => 
                    [times_redeemed] => 3
                    [valid] => 1
                )

            [customer] => cus_B0NaauYAdsB4KG
            [end] => 
            [start] => 1499773624
            [subscription] => sub_B0NaTziRwmZEtW
        )

    [ended_at] => 
    [items] => Array
        (
            [object] => list
            [data] => Array
                (
                    [0] => Array
                        (
                            [id] => si_1AeMpYIsl5Iu1a42o9vIyzMN
                            [object] => subscription_item
                            [created] => 1499773624
                            [plan] => Array
                                (
                                    [id] => deluxe
                                    [object] => plan
                                    [amount] => 4999
                                    [created] => 1484583859
                                    [currency] => usd
                                    [interval] => month
                                    [interval_count] => 1
                                    [livemode] => 
                                    [metadata] => Array
                                        (
                                        )

                                    [name] => Deluxe
                                    [statement_descriptor] => live24u - deluxe
                                    [trial_period_days] => 21
                                )

                            [quantity] => 1
                        )

                )

            [has_more] => 
            [total_count] => 1
            [url] => /v1/subscription_items?subscription=sub_B0NaTziRwmZEtW
        )

    [livemode] => 
    [metadata] => Array
        (
        )

    [plan] => Array
        (
            [id] => deluxe
            [object] => plan
            [amount] => 4999
            [created] => 1484583859
            [currency] => usd
            [interval] => month
            [interval_count] => 1
            [livemode] => 
            [metadata] => Array
                (
                )

            [name] => Deluxe
            [statement_descriptor] => live24u - deluxe
            [trial_period_days] => 21
        )

    [quantity] => 1
    [start] => 1499773624
    [status] => trialing
    [tax_percent] => 
    [trial_end] => 1500374577
    [trial_start] => 1499773624
)

Example

I hope you have Got What is php – Stripe API subscriptions And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.