user upgrades: upgrade to new Stripe checkout system.

This upgrades from the legacy version of Stripe's checkout system to the
new version:

> The legacy version of Checkout presented customers with a modal dialog
> that collected card information, and returned a token or a source to
> your website. In contrast, the new version of Checkout is a smart
> payment page hosted by Stripe that creates payments or subscriptions. It
> supports Apple Pay, Dynamic 3D Secure, and many other features.

Basic overview of the new system:

* We send the user to a checkout page on Stripe.
* Stripe collects payment and sends us a webhook notification when the
  order is complete.
* We receive the webhook notification and upgrade the user.

Docs:

* https://stripe.com/docs/payments/checkout
* https://stripe.com/docs/payments/checkout/migration#client-products
* https://stripe.com/docs/payments/handling-payment-events
* https://stripe.com/docs/payments/checkout/fulfill-orders
This commit is contained in:
evazion
2020-12-23 05:15:08 -06:00
parent c17678d509
commit 7762489d7d
18 changed files with 536 additions and 175 deletions

View File

@@ -0,0 +1,55 @@
{
"id": "evt_000",
"object": "event",
"api_version": "2020-08-27",
"created": 1608705740,
"data": {
"object": {
"id": "cs_test_000",
"object": "checkout.session",
"allow_promotion_codes": null,
"amount_subtotal": 2000,
"amount_total": 2000,
"billing_address_collection": null,
"cancel_url": "http://localhost/user_upgrade/new",
"client_reference_id": "user_12345",
"currency": "usd",
"customer": "cus_000",
"customer_email": null,
"livemode": false,
"locale": null,
"metadata": {
"purchaser_id": "12345",
"recipient_id": "12345",
"purchaser_name": "user_12345",
"recipient_name": "user_12345",
"upgrade_type": "gold_upgrade",
"is_gift": "false",
"level": "30"
},
"mode": "payment",
"payment_intent": "pi_000",
"payment_method_types": [
"card"
],
"payment_status": "paid",
"setup_intent": null,
"shipping": null,
"shipping_address_collection": null,
"submit_type": null,
"subscription": null,
"success_url": "http://localhost/user_upgrade?user_id=12345",
"total_details": {
"amount_discount": 0,
"amount_tax": 0
}
}
},
"livemode": false,
"pending_webhooks": 3,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}

View File

@@ -0,0 +1,67 @@
{
"id": "evt_000",
"object": "event",
"api_version": "2020-08-27",
"created": 1608705945,
"data": {
"object": {
"id": "pi_000",
"object": "payment_intent",
"amount": 2000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_000"
},
"client_secret": "pi_000",
"confirmation_method": "automatic",
"created": 1608705945,
"currency": "usd",
"customer": null,
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}
},
"livemode": false,
"pending_webhooks": 3,
"request": {
"id": "req_000",
"idempotency_key": null
},
"type": "payment_intent.created"
}