#paulh92-promo
1 messages · Page 1 of 1 (latest)
@noble rivet we can try, but we don't know anything about Lavarel specifically here. But what's the question?
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
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?
Hm, and that seems to be for confirming a setup intent, so that doesn't seem to be what we're looking for.
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