cartalyst / stripe-laravel

Cartalyst Stripe package integration for Laravel.
BSD 3-Clause "New" or "Revised" License
336 stars 58 forks source link

Using idempotency_key #42

Closed blorange2 closed 5 years ago

blorange2 commented 5 years ago

When using your package to create a charge I had an issue where a user could click the submit button multiple times and submit multiple charges.

I read in the official Stripe documentation that you can set a idempotency_key on the Charge object to avoid such situations.

So, I tried the following:

$charge = $stripe->charges()->create([
    'amount' => $amount,
    'currency' => $currency,
    'card' => $token,
    'description' => $description,
    'statement_descriptor' => 'Newable Ventures',
    'receipt_email' => $user->email
  ], [
        "idempotency_key" => $user->id
  ]);

I also see that the package uses a Stripe config file at vendor\cartalyst\stripe\src\Config.php

This file contains the following:

/**
 * {@inheritdoc}
 */
public function setIdempotencyKey($idempotencyKey)
{
    $this->idempotencyKey = $idempotencyKey;

    return $this;
}

So, you can set it, however when I send the request I do not see the additional key anywhere.

brunogaspar commented 5 years ago

The key, after you set it, is going to be passed here https://github.com/cartalyst/stripe/blob/2.0/src/Api/Api.php#L188

If the feature doesn't work as intended, please open the issue here as this is the Laravel bridge package and if you can submit a pull request.

blorange2 commented 5 years ago

Is there any way I could view the headers for the request?