Developer Tools
Idempotency
Sending a create twice with the same Idempotency-Key header returns the original result instead of creating a second resource. This runs the same payment intent create twice with one key.
Every demonstration here makes a real PayMongo API call in test mode. Nothing is simulated, and no real money moves.
- PayMongo stores the result of the first request made with a key and returns it for every repeat of that key, for 24 hours.
- A repeat with the same key but different parameters is rejected rather than applied.
- The package adds a fresh key to every POST automatically while PAYMONGO_AUTO_IDEMPOTENCY is on, so its own retries of that one call never create a duplicate.
- An automatic key is new on every call, so it does not protect against your application calling create twice, such as a double form submission. Pass your own key, derived from your order, for that.
- Only the payment intent, checkout session, payment link, and refund creates take your own key, as an idempotencyKey argument.
The same create, twice, with one key
PHP
use Illuminate\Support\Str;
use Luigel\Paymongo\Facades\Paymongo;
public function createTwice(): array
{
$key = (string) Str::uuid();
$attributes = [
'amount' => 10000,
'currency' => 'PHP',
'payment_method_allowed' => ['card'],
'description' => 'Playground idempotency demonstration',
];
$first = Paymongo::paymentIntents()->create($attributes, idempotencyKey: $key);
$second = Paymongo::paymentIntents()->create($attributes, idempotencyKey: $key);
return ['key' => $key, 'first' => $first, 'second' => $second];
}