1 $checkout_session = \Stripe\Checkout\Session::create([
2 'line_items' => [[
3 # Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
4 'price' => '对应产品目录的API ID',
5 'quantity' => 10, // 数量默认为1,我这边产品单价是1,
6 ]],
7 'mode' => 'payment', // 结账模式 付款
8 'success_url' => $YOUR_DOMAIN . '/success.html', // 支付成功跳转的页面
9 'cancel_url' => $YOUR_DOMAIN . '/cancel.html', // 取消支付跳转的页面
10 'automatic_tax' => [
11 'enabled' => true,
12 ],
13 ]);
1 $checkout_session = \Stripe\Checkout\Session::create([
2 'line_items' => [[
3 # Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
4 'price' => '对应产品目录的API ID',
5 'quantity' => 10, // 数量默认为1,我这边产品单价是1,
6 ]],
7 'mode' => 'payment', // 结账模式 付款
8 'success_url' => $YOUR_DOMAIN . '/success.html', // 支付成功跳转的页面
9 'cancel_url' => $YOUR_DOMAIN . '/cancel.html', // 取消支付跳转的页面
10 'automatic_tax' => [
11 'enabled' => true,
12 ],
13 // 元数据
14 'metadata' => [
15 'order_id' => 'you order id',
16 'product_name' => 'prodct name'
17 ]
18 ]);
1 // 回调端点密钥,从webhook获取
2 $endpointSecret = '端点密钥';
3 // 获取参数
4 $payload = @file_get_contents('php://input');
5 $sigHeader = $_SERVER['HTTP_STRIPE_SIGNATURE'];
6 // 签名验证
7 try {
8 $event = Webhook::constructEvent(
9 $payload,
10 $sigHeader,
11 $endpointSecret
12 );
13 } catch (SignatureVerificationException $e) {
14 // 签名验证失败
15 log_message('签名验证失败', 'log', 'pay');
16 http_response_code(400);
17 exit();
18 }
19 // 订单处理
20 if ($event->type != 'checkout.session.completed') {
21 log_message('返回的type是:' . $event->type, 'log', 'pay');
22 http_response_code(400);
23 exit();
24 }
25
26 // todo 此处处理成功之后的业务逻辑
27
28 // 处理成功返回200状态码
29 http_response_code(200);
30
{
"id": "evt_你看不见",
"object": "event",
"api_version": "2023-10-16",
"created": 1709170566,
"data": {
"object": {
"id": "cs_test_你看不见",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 1000,
"amount_total": 1000,
"automatic_tax": {
"enabled": true,
"liability": {
"type": "self"
},
"status": "complete"
},
"billing_address_collection": null,
"cancel_url": "http://localhost:4242/cancel.html",
"client_reference_id": null,
"client_secret": null,
"consent": null,
"consent_collection": null,
"created": 1709170549,
"currency": "cny",
"currency_conversion": null,
"custom_fields": [
],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": {
"address": {
"city": null,
"country": "CN",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "你看不见",
"name": "你看不见",
"phone": null,
"tax_exempt": "none",
"tax_ids": [
]
},
"customer_email": null,
"expires_at": 1709256949,
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {
},
"rendering_options": null
}
},
"livemode": false,
"locale": null,
"metadata": {
"order_id": "you order id",
"product_name": "prodct name"
},
"mode": "payment",
"payment_intent": "pi_你看不见",
"payment_link": null,
"payment_method_collection": "if_required",
"payment_method_configuration_details": {
"id": "pmc_你看不见",
"parent": null
},
"payment_method_options": {
},
"payment_method_types": [
"card",
"alipay",
"wechat_pay",
"link"
],
"payment_status": "paid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"setup_intent": null,
"shipping_address_collection": null,
"shipping_cost": null,
"shipping_details": null,
"shipping_options": [
],
"status": "complete",
"submit_type": null,
"subscription": null,
"success_url": "http://localhost:4242/success.html",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"ui_mode": "hosted",
"url": null
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}