laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
239 stars 57 forks source link

Coupon Code is not applied when using "withCoupon()"? #4

Closed stefanzweifel closed 4 years ago

stefanzweifel commented 4 years ago

Description:

I'm trying to apply a coupon to a pay link by using the SubscriptionBuilder and the withCoupon()-method.

In my app, the checkout process looks like this:

  1. User selects a planfrom a list of plans and adds an optional coupon code and submits the form
  2. Controller builds PayLink and redirects user to Paddle (I'm not using the inline Checkout right now)
  3. User completes checkout on Paddle and is redirected back to the app

However, the coupon code doesn't seem to be applied. The price is not reduced and the user still has the option to add the coupon again by clicking "Add Coupon". (The coupon is valid as it's being applied when doing on paddle.com)

While debugging I've seen, that the coupon is available during the buildPayload-method call. The value is also still present before calling Cashier::post() here

I have the problem both with "Checkout" and "Product" Coupons.

Steps To Reproduce:

Build a paylink by using withCoupon().

$payLink = $user->newSubscription('default', $paddlePlanId)
    ->returnTo(route('home'))
    ->withCoupon('NAME-OF-COUPON')
    ->create();

return redirect($payLink);
alzaabi98 commented 4 years ago

I am not able to build paylink using this code

  $payLink = $user->newSubscription('default',  $paddlePlanId)
            ->returnTo(route('home'))
            ->create();

I got blank screen,

anyone has similar issues

    "laravel/cashier-paddle": "^1.0@beta",
    "laravel/framework": "^7.0",
    "php": "^7.2.5",
driesvints commented 4 years ago

@stefanzweifel I can confirm this doesn't work. I'll pick this up with Paddle.

driesvints commented 4 years ago

@alzaabi98 that works perfectly for me. I think that might be due to a network issue on your end? Maybe best to pick up with Paddle itself.

driesvints commented 4 years ago

@stefanzweifel I just tested this again and Product coupons work for me. Can you please share your exact setup of products and the product coupon?

kieran-paddle commented 4 years ago

Hi @stefanzweifel, there is a known issue with checkout coupons and the pay link API that cashier makes use of. As Dries has mentioned, there shouldn't be an issue with product coupons so we'd encourage you to use them for the time being.

I've added this thread to our bug tracker and will endeavour to keep you updated when a fix is pushed out.

alzaabi98 commented 4 years ago

@driesvints I was able to make it via normal paddle href with plan id. I am not sure why I am getting blank screen with no errors. I dont think it is network issue. Do you have full sample to test method in laravel ? thanks

driesvints commented 4 years ago

@alzaabi98 the snippet you posted is the full example.

alzaabi98 commented 4 years ago

@alzaabi98 the snippet you posted is the full example.

so " ->returnTo(route('home'))" does not mean to route to home after you get url ? I thought it means that..

Now I changed my code this way and it worked :


  $payLink = $user->newSubscription('default', 'planId')
            ->returnTo(route('home'))
            ->create();

        return view('home')->with('payLink', $payLink);
driesvints commented 4 years ago

I'm not really sure what's unclear in the docs. The docs here tell you to use the pay link in a Blade component:

Screenshot 2020-06-11 at 16 05 46

driesvints commented 4 years ago

Further down at subscriptions it also notes:

The returnTo method accepts a URL that your user will be redirected to after they successfully complete the checkout.

alzaabi98 commented 4 years ago

Further down at subscriptions it also notes:

The returnTo method accepts a URL that your user will be redirected to after they successfully complete the checkout.

I thought returnto mean will route you to home to see the button but it means when you complete the transaction it will route you back. my be my mistake .. thanks

stefanzweifel commented 4 years ago

@driesvints @kieran-paddle Thanks for the info about checkout-coupons. After thinking about a minute about it, this makes total sense to me (as a paylink is for a product subscription).

My reported bug was a mistake on my side however. Forgot to link the product-coupon with my plans 🤦 Now everything works as expected.

Sorry for the noise :)

driesvints commented 4 years ago

@stefanzweifel glad you found a fix 👍

I'm gonna leave this open a while longer to follow up until Paddle has fixed checkout coupons.

Benoit1980 commented 4 years ago

Just to let you know, I got caught with the exact same issue from your doc. I thought that: ->returnTo(route('home'))

Was the actual returned view until I saw this post and this:

  $payLink = $user->newSubscription('default', 'planId')
            ->returnTo(route('home'))
            ->create();

        return view('home')->with('payLink', $payLink);

A lot of people will get caught with this I believe. It would be nice to have this added to the example in your doc: return view('home')->with('payLink', $payLink);

Thanks

driesvints commented 4 years ago

Yeah I agree. I sent in a pr here: https://github.com/laravel/docs/pull/6109

kieran-paddle commented 4 years ago

@driesvints(and anyone else following this), I pushed a fix for checkout coupons today so they will now work for checkouts generated with the pay link API. Sorry it took a little while to get out!

driesvints commented 4 years ago

Works again indeed! Thanks @kieran-paddle.