laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 671 forks source link

Proper support for ad-hoc pricing #1040

Closed benjamindoe closed 3 years ago

benjamindoe commented 3 years ago

Stripe offers the ability to create ad-hoc prices through their API. It essentially just creates an archived price on a specified product. You can currently do this just fine with the Stripe SDK but it was be nice to just be able to use the swap method on a subscription.

This is a useful feature when either migrating to Stripe from another payment system or migration from single plan subscriptions to multiplan subscriptions. I'm sure there are other use cases for this but only these come to mind.

Currently, this is technically possible to do in Cashier, but it's not the most elegant solution.

$user->newSubscription('default', [])->create($paymentMethod, [], [
    'items' => [['price_data' => [
        'unit_amount' => 1000,
        'currency' => 'USD'
    ]]],
]);

This work around could have also be done with swaps, however if you pass an empty array into the swap function, an InvalidArgumentException is thrown.

https://stripe.com/docs/billing/prices-guide#ad-hoc

Originally posted by @benjamindoe in https://github.com/laravel/cashier-stripe/issues/956#issuecomment-746036518

driesvints commented 3 years ago

I'll mark this as an enhancement but it's unlikely we'll be working on this ourselves as it doesn't strikes me as a widely adopted feature.

dejavuejs commented 3 years ago

I'll mark this as an enhancement but it's unlikely we'll be working on this ourselves as it doesn't strikes me as a widely adopted feature.

This enhancement has a proper valid use case and scenario. Just take a look a Amazon pantry's subscribe feature. When selling products as subscription in ecommerce we cannot create plans for products in ecommerce store.

I have implemented this in one of my projects and if really required i can make a PR too.

driesvints commented 3 years ago

Always free to attempt a PR 👍

dejavuejs commented 3 years ago

Always free to attempt a PR 👍

Surely, i will do it.

Thanks.

driesvints commented 3 years ago

I'm unfortunately going to close this one as we won't be working on this ourselves anytime soon. If anyone wants to send in a PR that implements this in a really clean way that does't requires too much code changes we're welcoming PRs.

atta1234 commented 3 years ago

Stripe offers the ability to create ad-hoc prices through their API. It essentially just creates an archived price on a specified product. You can currently do this just fine with the Stripe SDK but it was be nice to just be able to use the swap method on a subscription.

This is a useful feature when either migrating to Stripe from another payment system or migration from single plan subscriptions to multiplan subscriptions. I'm sure there are other use cases for this but only these come to mind.

Currently, this is technically possible to do in Cashier, but it's not the most elegant solution.

$user->newSubscription('default', [])->create($paymentMethod, [], [
    'items' => [['price_data' => [
        'unit_amount' => 1000,
        'currency' => 'USD'
    ]]],
]);

This work around could have also be done with swaps, however if you pass an empty array into the swap function, an InvalidArgumentException is thrown.

https://stripe.com/docs/billing/prices-guide#ad-hoc

Originally posted by @benjamindoe in #956 (comment)

Hello i really need this feature, i tried this one

$subscription = \Stripe\Subscription::create([ 'customer' => $user->stripe_id, 'items' => [[ 'price_data' => [ 'unit_amount' => 4000, 'currency' => 'gbp', 'product' => 'prod_JJwrtNNxtL5T2x', 'recurring' => [ 'interval' => 'month', ], ], ]], ]);

exit(); it's working but if user already has payment method, not working for a new customer, can you help?

driesvints commented 3 years ago

@atta1234 please try a support channel:

atta1234 commented 3 years ago

if anyone struggling with this, this solution is working, $user->newSubscription('default', [0])->create($paymentMethod, [], [ 'items' => [['price_data' => ['unit_amount' => $customamount*100, 'currency' => 'gbp', 'product' =>$productid, 'recurring' => [ 'interval' => 'month', ],]]], ]);