1
votes

Could you guy please show me how to create a Stripe Charge which can apply the discount automatically.

  1. I have a valid coupon code (expired in far future, forever use, discount $2).
  2. I create a new Stripe user and assign that Coupon Code for him.
  3. I make a Charge with that customer and some money says: amount = $10.

All the thing works. When I login to Stripe Dashboard, I still see the new user in the list and he is using that Coupon Code. However in the payment, he still pay me $10 instead of $8.

I would like to make a Charge with amount = $10, however Stripe will do discounting so the true Charge will pay $8 only.

$myCard = array(
  'number' => '4242424242424242',
  'exp_month' => 12,
   'exp_year' => 16
);

$coupon  = Coupon::retrieve('6868');
//Valid coupon
$stripe_customer = Customer::create(array(
    'card' => $myCard,
    'email' => '[email protected]',
    'coupon' => $coupon
));

$charge = Charge::create(array(
    'customer' => $stripe_customer->id,
    'amount' => 1000,
    'currency' => 'usd'
));
1
Coupons only apply to invoices not charges, you should just discount it yourselfMatthew Arkin
Yes, you're right. I used Invoice successfully. Thanks so much.Trang
I don't recommend invoices for one-off charges, they should be kept to just the subscription workflow. Invoices will do things like wait 1 hour to be charged, auto retry on failed payments, etcMatthew Arkin
I understand. However, I need Discount to be auto right now. I will try to make the Discount manually, thanks.Trang
The proper way would be to just tell Stripe the amount is 800 ($8) instead of 1000 ($10)Matthew Arkin

1 Answers

0
votes

Stripe does not allow coupons/discounts for one time payments because you don't really need Stripe to handle your coupons for one-time payments.

You need coupons for subscriptions because Stripe generates a subscription's charges automatically, by itself, on its own schedule. That means your code has no opportunity to modify the amount of the charge itself. Instead, you have to modify the subscription, which then modifies the charges it generates in the future. Stripe offers three simple ways to do this: changing the plan, setting the account balance, and adding invoice items. However, none of them allow you to specify a percentage discount or apply a modification for more than just the next invoice but less than forever. Coupons fix that issue.

A one-time charge, on the other hand, is always generated by you, so you always have an opportunity to modify the amount of the charge yourself. The problem that coupons are trying to solve doesn't exist here, so they aren't offered as an option.

reference : click here