laravel 对接stripe支付

article/2025/4/20 0:31:10
  1. 参考文档 :
    stripe文档
    stripe/stripe-php
    stripe api 文档

目录

  • 一 获取关键参数
  • 二 安装Stripe库
  • 三 代码示例

一 获取关键参数

SCRIPE_SECRET_KEY (调用api秘钥)
NOTIFY_SIGN (签名 支付回调使用)

二 安装Stripe库

# Install the PHP library via Composer
composer require stripe/stripe-php

三 代码示例

// 支付请求主要代码$stripe = new StripeClient(env('SCRIPE_SECRET_KEY'));$checkoutSession = $stripe->checkout->sessions->create(['success_url' =>  $success_url,  // 付款或设置完成后,Stripe 应将客户发送到的 URL。'cancel_url' => $cancel_url,		// 如果客户决定取消付款并返回您的网站,他们将被定向到的 URL。'payment_method_types' => ['card','alipay'],  // 选择支付方式'locale'=>'auto', // auto:Stripe检测浏览器的语言环境'line_items' => [['currency' => 'usd',  // 支付货币类型(每个货币的 ISO 代码)'amount' => 100,  //所有 API 请求都期望金额以货币的最小单位提供。例如,要收款 10 USD,提供一个值为 1000 的 amount(即 1000 美分)'name' => 'Payment', //产品的名称,旨在向客户展示。每当通过订阅销售此产品时,名称将显示在相关的发票行项目描述中。'quantity' => 1,  //正在购买的项目的数量'description'=>"自定义支付页面提示信息", //产品的描述,旨在向客户展示。使用此字段可选择存储所售产品的长格式说明,用于您自己的渲染目的。],],'mode' => 'payment', // payment:接受卡、iDEAL 等的一次性付款。setup:保存付款详细信息,以便以后向您的客户收费。subscription:使用 Stripe Billing 设置固定价格订阅。]);// 支付回调主要代码
Stripe::setApiKey(env('SCRIPE_SECRET_KEY'));$endpoint_secret = env('NOTIFY_SIGN');
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;  // 回调返回的数据
try {$event = Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
} catch(\UnexpectedValueException $e) {// Invalid payloadhttp_response_code(400);exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {// Invalid signaturehttp_response_code(400);\Log::info('签名异常信息'.$e->getMessage());exit();
}
// Handle the event
switch ($event->type) {case 'payment_intent.succeeded':$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntenthandlePaymentIntentSucceeded($paymentIntent);break;case 'payment_method.attached':$paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethodhandlePaymentMethodAttached($paymentMethod);break;// ... handle other event typesdefault:echo 'Received unknown event type ' . $event->type;
}

http://chatgpt.dhexx.cn/article/IoCe9Re0.shtml

相关文章

Stripe支付配置

开通支付 首先,你需要在 Stripe 官网开通你自己的支付账号信息: https://stripe.com/ 注册好以后,你即可获取 Stripe 的密钥信息: 密钥主要包含两部分,可发布的密钥 密钥 同时,你需要找到你交易的对应的货…

php实现Stripe支付 | ecshop stripe支付

Stripe支付 :Stripe Login | Sign in to the Stripe Dashboard 1. 安装Stripe: composer require stripe/stripe-php 2. 获取密钥:https://dashboard.stripe.com/test/apikeys 3. 创建产品:Stripe Login | Sign in to the Stri…

php实现Stripe支付

Stripe支付 :https://dashboard.stripe.com/dashboard 1. 安装Stripe: composer require stripe/stripe-php 2. 获取密钥: https://dashboard.stripe.com/test/apikeys 3. 创建产品: https://dashboard.stripe.com/test/product…

stripe 支付

stripe 支付整理 1、创建账号 官方网址 中文版 https://stripe.com/zh-cn-us/payments 2、激活你的账号 填写信息只支持国外与香港的哦 3、开发者秘钥 如果不激活的话,只能用测试api秘钥 4、配置你的回调地址 配置秘钥,选择webhook事件 事件一定要选择…

java 对接 stripe支付

stripe 支付跟国内的 支付宝 、微信、等第三方支付平台不一样 码字不易,开源更不易,点赞收藏关注,多多支持 开源地址 https://gitee.com/J-LJJ/stripe-demo 支付方式一 先看效果 支付方式2(需要配合回调) 2023-04…

Stripe支付流程简要描述

在国外,除了Paypal支付之外,Stripe支付也占有很大一部分市场份额,Stripe支付官网 https://stripe.com/ 下面简单介绍一下Stripe的支付流程。 1、用户页面输入充值金额,点击确定跳转到支付页面(页面的样式由stripe提供…

stripe支付集成

最近公司要做一下Stripe支付的集成,浅浅地谈一下自己的一点理解 1、stripe是什么? stripe是第三方的支付平台,就像国内的支付宝、微信支付。。。 stripe官方文档:Developer tools | Stripe Documentation 关于stripe支付&…

初步认识 Stripe 支付

前言 这段时间在做支付相关的工作,由于业务主要是面向国外的用户,因而就接触了部分国外的支付支付相关的平台。接下来的内容主要是初步看了 Stripe 平台的文档所了解到的基本内容,后面会在使用的过程中不断地进行完善。 基本介绍和与其他支…

Stripe支付流程

近几天因为公司的项目中遇到了需要支持给国外本土支付提供支持,经过调研了市面上几款的产品后选择了stripe支付 由于资料比较少没有太多讨论,慢慢查看官方文档以下是我对官方文档梳理和对接过程中的一些经验和理解记录了下来 关于Stripe Stripe是一家提…

Stripe国际支付简介及API对接

文章目录 一、了解Stripe支付二、Stripe注册流程三、Stripe API 特点3.1 Apikey3.2 Idempotent Requests 幂等请求3.3 两种付款方式 四、Stripe 支付核心API4.1 Token4.2 Customer4.3 Card4.4 Source4.5 charge4.6 PaymentIntents4.7 PaymentMethod 五、完整Stripe支付代码 一、…

mingw(msys2)编译ffmpeg

mingw(msys2)编译ffmpeg 首先要确保pacman环境是最新的,否则会出现莫名其妙的问题,可以执行“pacman -Syu”更新包 安装mingw: pacman -S gcc mingw-w64-i686-toolchain yasm mingw-w64-i686-SDL2 //mingw32 pacman -S gcc mingw-w64-x86_64-toolchai…

Hyperscan Windows 编译指南

Hyperscan Windows 编译指南 Hyperscan 源码下载:https://www.hyperscan.io/准备环境: Windows 10 X64 Cygwin : https://www.cygwin.com/ CMake:https://cmake.org/ Visual Studio 2017 Python (2.7 版本) Boost : https://www.boost…

Hyperscan 5.4.0 安装教程 (CentOS7环境)

参考:Getting Started — Hyperscan 5.4.0 documentationhttp://intel.github.io/hyperscan/dev-reference/getting_started.html 目录 1.下载 2.安装环境配置 2.1 硬件需求 2.2 软件需求 3.安装 3.1 创建构建目录 3.2 设置编译选项 3.3 构建hyperscan 4.安…

Hyperscan 安装

源码下载 Ragel :http://www.colm.net/files/ragel/ragel-6.9.tar.gz boost :http://downloads.sourceforge.net/project/boost/boost/1.60.0/boost_1_60_0.tar.gz hyperscan : https://download.csdn.net/download/u014608280/12745509 第…

centos 8 编译安装hyperscan

一、编译安装环境配置 官方文档: http://intel.github.io/hyperscan/dev-reference/getting_started.html 1.1硬件配置 配置参数CPUIntel Xeon Gold 5218R CPU 2.10GHzCPU核数8核 注:需要满足以下条件 1、X86架构 2、Supplemental Streaming SIMD E…

ubuntu20.04下源码安装hyperscan库安装记录

安装测试环境: vmware-ubuntu20.04,gcc 4.8.5,ragel-6.10.tar.gz,boost_1_69_0.tar.gz,hyperscan-5.1.0.tar.gz 1.安装ragel(必须的依赖包)1MB: 下载地址:http://www.…

基于CentOS 8 系统环境下的 Snort 3 安装指南

O、 阅读要求 本教程并不适合初学者,大家在阅读本文之前,需具备CentOS 8 Linux、Snort 2.9的成功安装经验。本次安装对网络依赖很大,所以大家一定要将网络状态调节好,本指南介绍的内容,仅在测试环境中使用。 一、环境…

msys2+mingw64+ragel安装

[msys2mingw64ragel安装] [简介] 这几天部门老大让解析几个东西,要求用ragel编写,在Windows环境下,要运用到mingw64,安装时发现mingw里没有pacman,需要现安装,然后发现Wget也没有。。。,所以改…

Ragel State Machine Compiler 的速度测试

据说Ragel生成的自动机程序,速度飞快,特地测试了一下,所得结果如下。 测试环境: VC6 Release下编译 测试规模: 一亿次 测试用例: Ragel编译r_atoi.rl文件 vs crt lib的 atoi函数 测试结果&…

Hello Ragel -- 生成状态机的神器

Ragel 是个很 NB 的能生成状态机的编译器,而且支持一堆语言:C、C、Object-C、C#、D、Java、Go 以及 Ruby。 原来的文本解析器是用正则表达式实现的,随着状态(if-else)越来越多,修改越来越麻烦。。。 安装 M…