Export transactions require a customer name and address – Stripe Error
Few days back, I encountered this error “Export transactions require a customer name and address” while integrating Stripe payment gateway with my Laravel application.
Overview
I have used the Laravel Cashier(stripe) package to integrate the stripe payment gateway.
In our case, User is the billable model and we have ShippingAddress
model to store the user address. After this, we have SubscriptionController
to create a new subscription for the user and SingleChargeController
to make a direct one time charge for the user.
Now, while making a single charge and while creating a new subscription, I got this error “Export transactions require a customer name and address”.
While creating new subscription with stripe
In the SubscriptionController
while creating a new subscription, we can sync stripe customer details.
protected function subscribe(Request $request, User $user, Plan $planItem) { $user->syncStripeCustomerDetails(); $user->newSubscription('standard', $planItem->price_id) ->create($request->payment_method); }
It basically uses syncStripeCustomerDetails
method from the Laravel\Cashier\Billable trait.
/** * Sync the customer's information to Stripe. * * @return \Stripe\Customer */ public function syncStripeCustomerDetails() { return $this->updateStripeCustomer([ 'name' => $this->stripeName(), 'email' => $this->stripeEmail(), 'phone' => $this->stripePhone(), 'address' => $this->stripeAddress(), ]); }
As we can see in the above code, address is fetched from stripeAddress
method of the Billable trait. I have overridden this method in my Billable model User as below.
public function stripeAddress() { $shippingAddress = $this->shippingAddress; return [ 'line1' => $shippingAddress->line1 ?? ' ', 'postal_code' => $shippingAddress->zip_code ?? ' ', 'city' => $shippingAddress->city ?? ' ', 'state' => $shippingAddress->state ?? ' ', 'country' => $shippingAddress->country ?? ' ', ]; }
Finally Billable model
Finally our billable model will look like below, although I have a lot of other stuff in this model, but these are useful for this stripe issue.
class User extends Authenticatable implements MustVerifyEmail { public function shippingAddress() { return $this->morphOne(ShippingAddress::class, 'user'); } public function stripeAddress() { $shippingAddress = $this->shippingAddress; return [ 'line1' => $shippingAddress->line1 ?? ' ', 'postal_code' => $shippingAddress->zip_code ?? ' ', 'city' => $shippingAddress->city ?? ' ', 'state' => $shippingAddress->state ?? ' ', 'country' => $shippingAddress->country ?? ' ', ]; } /** * Sync the customer's information to Stripe. * * @return \Stripe\Customer */ public function syncStripeCustomerDetails() { return $this->updateStripeCustomer([ 'name' => $this->stripeName(), 'email' => $this->stripeEmail(), 'phone' => $this->stripePhone(), 'address' => $this->stripeAddress(), ]); } }
While making single Charge with stripe
While making a single charge with stripe will also throw this error “Export transactions require a customer name and address”. So, below is the solution for this stripe error.
In the SingleChargeController
, I was using the below method to make a charge with stripe. I have passed the customer details and address as a meta in the charge method of Laravel\Cashier\Concerns\PerformsCharges
.
protected function createStripeCharge(User $user, float $amount, string $paymentMethod, string $meta_description) { $meta = $this->stripChargeMeta($user, $meta_description); return $user->charge(($amount*100), $paymentMethod, $meta); } protected function stripChargeMeta(User $user, string $description) { return [ 'description' => $description, 'shipping' => [ 'name' => $user->name, 'address' => $user->stripeAddress(), ] ]; }
Hope you found this tutorial useful, if yes then please share with your colleagues and comment below for more such tutorials.