I wanted to know if it is possible to not take credit card info when one of the drop down options for a subscriptions is a free plan.
So basically I have two plans. First is the basic plan and is free. The second is the premium plan and cost $20. When someone chooses the premium plan we capture their credit card info.
Now if someone chooses the free plan, is it possible to hide the credit card input fields when someone chooses the basic? And will stripe execute on it? Is there such an option on stripe?
thanks,
Yes you can hide the credit card option if this is a free subacription.
If you are using stripe.js then you can simply dissable the form based on your subscription plan.
Free subscriptions in Stripe don't require a card. Your application would need to recognize its a free plan and not require the credit card
yes You can do it based on your subscription plan.
you can create Free and Pro plan(paid) and take those to your drop down list.
when user select free plan hide your payment information capturing part and go further.
yeah that is possible,
try to use this example:
1:first create plan (In plan we can pass amount 0 for free subscription )
2:create customer
3:create subscription
public function createPlan($data)
{
$plan=\Stripe\Plan::create(array(
"amount" => $data['Amount'],
"interval" => $data['Interval'],
"name" => $data['planName'],
"currency" => "usd",
"id" => $data['planName'])
);
}
/*
* createcustomer function used to create customer for implementing recurring transactions rather asking again and again card details
*/
public function createCustomer($data,$token=null)
{
$customer=\Stripe\Customer::create(array(
"email"=>$data['email'],
"description" => $data['name'],
"source" => $token // obtained with Stripe.js
));
$this->subscribe($customer,$data);
}
public function subscribe($customer,$data)
{
$subsc=\Stripe\Subscription::create(array(
"customer" => $customer->id,
"plan" => $data['planName']
));
\Stripe\Subscription::create(array(
"customer" => customer['id'],
"plan" => "home-delivery",
));
}
Related
If this is the first time this specific customer pays for this specific subscription.
I must set the cancel_at field of the subscription based on the chosen plan ID. (I don't want to set it upon the creation of the subscription). To tackle this first time , I have captured the invoice.payment_succeeded event and I did the following:
$invoices = \Stripe\Invoice::all([
"limit" => 3, //no need to get all of the invoices just checking if their number is = 1.
"status" => 'paid',
"customer" => $customer_id,
"subscription" => $subscription_id,
"expand" => ["data.charge"],
]);
if ( count($invoices->data) == 1 ) {
//First time this user pays for this specific subscription;
Can You just tell me if it is right or if I missed anything as I am new to php as well as stripe. should I be doing count($invoices) instead of what i did ?
Your code looks fine, but the only way to tell if it'll work or not is for you to run it and see if it does what you expect it to do. You can use your test mode API keys and the Stripe CLI to test the flow:
stripe trigger customer.subscription.created
This will create a test customer, a plan and a subscription. The latter will immediately create and pay an invoice, so you should get a invoice.payment_succeeded webhook event to test with.
I'm using Stripe to charge the user in a food ordering app, I can save theyr card and charge them just fine.
But I'm facing a problem, I'm from Brazil and here we have cards that can be both Credit and Debit. I can't figure out how to tell the payment method which funding to use.
Here's how I'm creating the payment method:
var options = new PaymentMethodCreateOptions
{
Card = new PaymentMethodCardOptions
{
Number = number,
Cvc = cvc,
ExpMonth = long.Parse(expMonth),
ExpYear = long.Parse(expYear)
},
Type = "card",
};
I'm using 'card' as the type right now, but it seems to default to charging the card as Credit Card.
Looking through the api documentation I can specify the type as:
alipay, au_becs_debit, bacs_debit, bancontact, card, eps, fpx, giropay,
grabpay, ideal, oxxo, p24, sepa_debit, sofort
I can't find a way to tell Stripe to charge the card as a Debit Card.
Is it possible for me to tell stripe which type of funding should be used to process the payment in this situation?
There isn't a way to ask Stripe to charge a card as a "debit" or a "credit" card. There also isn't really a difference in charging either a debit/credit card when you create a Charge, Stripe just charges both cards the same way.
I'd like to show a customer a preview (or a quote) of what their subscription charges will be if they make changes to their subscription. For this, I'm using the "upcoming invoice" API endpoint:
https://stripe.com/docs/api/invoices/upcoming
From that link, they state that "You can preview the effects of updating a subscription, including a preview of what proration will take place.".
When changing plans, you have to first fetch the current subscription item ID (https://stripe.com/docs/api/subscription_items), and specify "deleted" => true. Then you add the new plan as a subscription_item.
Here's an example call:
[
"subscription" => "sub_GUw5iYoBYiSAEl"
"subscription_items" => [
[
"id" => "si_GUw53rbtqOpZYB"
"deleted" => true
],
[
"plan" => "plan_GAf8EkL1VIPYZ9"
"quantity" => "1"
]
]
]
This works great when the user is not in their trial period.
However, if the user is in their trial period, this only works if the billing interval of the plan you are changing to is the same. E.g. if you are on a monthly plan, changing to another monthly plan works.
If you are in your trial period on a monthly plan, and you are changing to a yearly plan (or vice versa), then it shows the upcoming invoice as $0.00 due today.
This also happens via the Stripe Dashboard:
Is there a way to show the actual amount, not $0.00?
You can pass subscription_trial_end to see what it would look like if the trial ended immediately.
I'm using Stripe's Checkout.
There is nothing that prevent me (apart my honesty) to display a low price to the customer, and then charge a higher price without his consent.
Did I miss something ? Is that an industry standard ? I believe it's not.
Why the token did not contain the user validated amount ?
Is it only in test mode ?
Thank you.
For exemple, this works (in test mode at least). I can see the high amount in my dashboard.
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="my_key"
data-amount="10"
data-currency="eur">
</script>
Then in the server side :
$charge = \Stripe\Charge::create(array(
"amount" => 10000,
"currency" => "eur",
"source" => $_REQUEST['stripeToken'],
));
You didn't miss anything -- it's up to each merchant to correctly display the amount and currency that will be used when actually charging their customers.
Failing to do would very likely result in disputes and chargebacks from your customers, which in turn could lead to your Stripe account being closed.
Could you guy please show me how to create a Stripe Charge which can apply the discount automatically.
I have a valid coupon code (expired in far future, forever use, discount $2).
I create a new Stripe user and assign that Coupon Code for him.
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' => 'cus#info.com',
'coupon' => $coupon
));
$charge = Charge::create(array(
'customer' => $stripe_customer->id,
'amount' => 1000,
'currency' => 'usd'
));
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