#paulh92-promo

1 messages · Page 1 of 1 (latest)

old edge
#

@noble rivet we can try, but we don't know anything about Lavarel specifically here. But what's the question?

noble rivet
#

thanks its basically that whenever we try a coupon code we get a 500 error

#

if (!empty($request->input('promotion_code'))) {
$codeId = $this->validatePromocode($request->input('promotion_code'));
\Auth::user()
->newSubscription('main', $plan)
->withPromotionCode($codeId)
->create($paymentMethod);

#

private function validatePromocode($promo)
{
try {
$promoCodes = Cache::remember('stripe-cache-promocodes', 600, function () {
$promos = PromotionCode::all(["active" => true]);
return $promos;
});
foreach ($promoCodes->data as $promoCode) {
if($promo==$promoCode->code) {
// valid
return $promoCode->id;
}
}
} catch (\Exception $e) {
return false;
}
}

#

i just pasted two functions there, ones checking the code input and returning its ID, then we pass that id into the subcription, works without a code, 500 errors with one so i assume the function im doing doesnt work right

lone grotto
#

When you get the 500, are there any details returned in that error and/or are you able to find a Stripe request ID (req_XXX) that we could take a closer look at?

noble rivet
#

this is the only error i see since

lone grotto
#

Hm, and that seems to be for confirming a setup intent, so that doesn't seem to be what we're looking for.

noble rivet
#

the other function works fine

#

its just this one

#

which contains these extra lines

#

$codeId = $this->validatePromocode($request->input('promotion_code'));

                \Auth::user()

** ->newSubscription('main', $plan)
** ->withPromotionCode($codeId)

#

imeant to highlight withPromotionCode there

#

i think its the validatePromocode function thats failing as its only started failing with that

lone grotto
#

Unfortunately we're getting down into the parts of Laravel Cashier that we don't understand well here.

#

I'll try to see what I can find, but I'm juggling several threads at the moment and may not find anything useful. The Laravel support team will likely be better suited to help out.