Created
March 8, 2022 18:28
-
-
Save tominal/5ee9ca2d88583762ed6b01f446231430 to your computer and use it in GitHub Desktop.
An example of Stripe Checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/../vendor/autoload.php'; | |
// This is a public sample test API key. | |
// Don’t submit any personally identifiable information in requests made with this key. | |
// Sign in to see your own test API key embedded in code samples. | |
\Stripe\Stripe::setApiKey('sk_test_key_here'); | |
header('Content-Type: application/json'); | |
$YOUR_DOMAIN = 'http://localhost:4242'; | |
$checkout_session = \Stripe\Checkout\Session::create([ | |
'customer_email' => 'customer@example.com', | |
'submit_type' => 'pay', | |
'billing_address_collection' => 'required', | |
'line_items' => [ | |
[ | |
"price_data" => | |
[ | |
'currency' => 'USD', | |
'product_data' => [ | |
'name' => "Product Name", | |
'description' => "Product description..." | |
], | |
'unit_amount_decimal' => 15000, | |
'tax_behavior' => "inclusive" | |
], | |
"quantity" => 2 | |
], | |
[ | |
"price_data" => | |
[ | |
'currency' => 'USD', | |
'product_data' => [ | |
'name' => "Card Fee", | |
'description' => "3% of total" | |
], | |
'unit_amount_decimal' => 900, | |
'tax_behavior' => "exclusive" | |
], | |
"quantity" => 1 | |
], | |
], | |
'mode' => 'payment', | |
'success_url' => $YOUR_DOMAIN . '/success.html', | |
'cancel_url' => $YOUR_DOMAIN . '/cancel.html', | |
'automatic_tax' => [ | |
'enabled' => false, | |
], | |
]); | |
// the payment intent contains an ID which can be used to redirect a customer service agent to the transaction | |
//var_dump($checkout_session->payment_intent); | |
//die(); | |
header("HTTP/1.1 303 See Other"); | |
header("Location: " . $checkout_session->url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment