0
votes

Ive been running into issues with Laravel Cashier when i deployed my app to heroku.

One my local environment everything is fine but on my staging server , no POST request body is ever sent to stripe.

I tried swapping api keys as i thought maybe the api version on stripe differs between the two but that doesn't work (see screenshots below)

Things i know are correct

  1. API creds , they wont show up on stripe logs if it wasent
  2. Composer version matches both environments (Laravel Cashier 10.5.2, Laravel 5.8.36, Stripe-php 17.7.0)

I cant seem to find anything that logs out going api requests. Ive even tried manually calling the stripe functions as low as i can get in the stack still no POST body.

Im sure some one else has ran into this. Google search on laravel cashier ALWAYS sends me back to the laravel website, like WTF.

this is my stripe method on my User model. All other code is from Cashier

public function activateSubscription() {
  if ($this->hasStripeId() &&
    $this->has_default_payment_method &&
    $this->has_active_subscription) {
    return;
  }

  try {
    $this->newSubscription(env('STRIPE_SUBSCRIPTION_NAME'), env('STRIPE_PLAN_ID'))
      ->create(null, [
        'name' => $this->fullname,
        'email' => $this->email,
      ]);

    $this->notify(new UserRegistered());
  } catch (\Stripe\Exception\InvalidRequestException $e) {
    Log::debug('Invalid Request', [
      'body' => $e->getHttpBody(),
      'headers' => $e->getHttpHeaders(),
      'json' => $e->getJsonBody(),
      'error_code' => $e->getStripeCode(),
    ]);
  }
}

Edit

Ive removed some personal details from the POST request body

Screenshot from stripe showing api request from staging on my local machine (dev Screenshot from stripe showing api request from staging on heroku

1
Can you provide the code that you're using the make the call, both with Laravel and when you take it down to the Stripe library directly?taintedzodiac
Ive added the code , when i call $user->createAsStripeCustomer(['name' => $user->fullname]) from my heroku console the stripe request contains non POST data either but a blank customer is created on stripe. note that this is laravel cashier code.purplenimbus

1 Answers

1
votes

I figured it out , i had a \n at the end of my stripe secret api key on heroku environment variables.

For some reason that caused all requests to stripe to strip the POST body.

Removed that, ran a php artisan config:clear and it worked