php实现Stripe支付 | ecshop stripe支付

article/2025/4/20 3:01:26

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 Stripe Dashboard

 

4. php 代码:

官方发起支付请求示例:https://stripe.com/docs/checkout/quickstart
 

/*** stripe支付*/
public function actionStripe()
{$_key = 'sk_test_51Jyo2iHnJH***********************************';// stripe 生成订单$url = 'https://www.baidu.com';\Stripe\Stripe::setApiKey($_key);$checkout_session = \Stripe\Checkout\Session::create(['line_items' => [['price' => {{PRICE_ID}}, // 产品id'quantity' => 1,]],'mode' => 'payment','success_url' => $url . '/success.html','cancel_url' => $url . '/cancel.html','automatic_tax' => ['enabled' => true,],]);$arrGoodsInfo['payment_intent'] = $checkout_session->payment_intent;// 创建本地订单操作,并payment_intent保留
//    ......//$checkout_session->url stripe跳转支付url// $checkout_session->payment_intent是识别支付与通知关系的唯一凭证return ['url' => $checkout_session->url, 'id' => $checkout_session->id, 'payment_intent' => $checkout_session->payment_intent];
}

出现tax_behavior 相关问题时需查看产品是否配置税务信息

var_dump($checkout_session);
结果:

array('id'                          => 'cs_test_a1SsLDn1NtwTzLa0JlOqH5Xr3nEUGvC2iQui0EFyedgTkpSrQhJDowfZ0E','object'                      => 'checkout.session','after_expiration'            => NULL,'allow_promotion_codes'       => NULL,'amount_subtotal'             => 400,'amount_total'                => 400,'automatic_tax'               =>array('enabled' => false,'status'  => NULL,),'billing_address_collection'  => NULL,'cancel_url'                  => 'https://www.baidu.com/cancel.html','client_reference_id'         => NULL,'consent'                     => NULL,'consent_collection'          => NULL,'currency'                    => 'hkd','customer'                    => NULL,'customer_creation'           => 'always','customer_details'            => NULL,'customer_email'              => NULL,'expires_at'                  => 1654681622,'livemode'                    => false,'locale'                      => NULL,'metadata'                    =>array(),'mode'                        => 'payment','payment_intent'              => 'pi_3L7z07IUnSe35qBJ0VC7FqLy','payment_link'                => NULL,'payment_method_options'      =>array(),'payment_method_types'        =>array(0 => 'card',),'payment_status'              => 'unpaid','phone_number_collection'     =>array('enabled' => false,),'recovered_from'              => NULL,'setup_intent'                => NULL,'shipping'                    => NULL,'shipping_address_collection' => NULL,'shipping_options'            =>array(),'shipping_rate'               => NULL,'status'                      => 'open','submit_type'                 => NULL,'subscription'                => NULL,'success_url'                 => 'https://www.baidu.com/success.html','total_details'               =>array('amount_discount' => 0,'amount_shipping' => 0,'amount_tax'      => 0,),'url'                         => 'https://checkout.stripe.com/pay/cs_test_a1SsLDn1NtwTzLa0JlOqH5Xr3nEUGvC2iQui0EFyedgTkpSrQhJDowfZ0E#fidkdWxOYHwnPyd1blpxYHZxWjA0STJfUkFMUGtWYDYwdEdPdWRrfUo9a3xNZndOYVJfTGxwdE5ATHdPfEAxaVA3Q1xNbnFMVUt2bzZQYGpvYHBmf11BPGRtZ2cyRFNHSGxBYl9jakNDSDU1NTV9aXNRPWNdXycpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl',
);

官方提供得测试账号:Testing | Stripe Documentation

支付成功会自动跳转到success.html

回调:
 

<?php
/*** 支付回调*/
namespace api\controllers;use yii\web\Controller;
use Yii;class PayNotifyController extends Controller
{/*** stripe支付回调*/public function actionStripe(){$_key = 'sk_test_51Jyo2iHnJH***********************************';\Stripe\Stripe::setApiKey($_key);$payload = @file_get_contents('php://input');$event = null;try {$event = \Stripe\Event::constructFrom(json_decode($payload, true));} catch(\UnexpectedValueException $e) {// Invalid payloadhttp_response_code(400);exit();}// Handle the eventswitch ($event->type) {case 'charge.succeeded':$succeeded = $event->data->object;$content = "=========".date('Y-m-d H:i:s',time())."==========\r\n";$content .= json_encode($succeeded);file_put_contents(dirname(__DIR__).'/runtime/logs/stripe_success.log',$content . "\r\n",FILE_APPEND);if ($succeeded->status == 'succeeded'){$payment_intent = $succeeded->payment_intent;}break;default:echo 'Received unknown event type ' . $event->type;break;}return true;}
}

我已成功接入ecshop。
转自:php实现Stripe支付_阿阿阿阿强的博客-CSDN博客_php stripe支付Stripe支付 :https://dashboard.stripe.com/dashboard1. 安装Stripe:composerrequirestripe/stripe-php2. 获取密钥:https://dashboard.stripe.com/test/apikeys3. 创建产品:https://dashboard.stripe.com/test/products4. php 代码:官方发起支付请求示例:https://stripe.com...https://blog.csdn.net/weixin_39461487/article/details/123260107


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

相关文章

php实现Stripe支付

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

stripe 支付

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

java 对接 stripe支付

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

Stripe支付流程简要描述

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

stripe支付集成

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

初步认识 Stripe 支付

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

Stripe支付流程

近几天因为公司的项目中遇到了需要支持给国外本土支付提供支持&#xff0c;经过调研了市面上几款的产品后选择了stripe支付 由于资料比较少没有太多讨论&#xff0c;慢慢查看官方文档以下是我对官方文档梳理和对接过程中的一些经验和理解记录了下来 关于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环境是最新的&#xff0c;否则会出现莫名其妙的问题&#xff0c;可以执行“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 源码下载&#xff1a;https://www.hyperscan.io/准备环境&#xff1a; Windows 10 X64 Cygwin : https://www.cygwin.com/ CMake&#xff1a;https://cmake.org/ Visual Studio 2017 Python (2.7 版本) Boost : https://www.boost…

Hyperscan 5.4.0 安装教程 (CentOS7环境)

参考&#xff1a;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 &#xff1a;http://www.colm.net/files/ragel/ragel-6.9.tar.gz boost &#xff1a;http://downloads.sourceforge.net/project/boost/boost/1.60.0/boost_1_60_0.tar.gz hyperscan &#xff1a; https://download.csdn.net/download/u014608280/12745509 第…

centos 8 编译安装hyperscan

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

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

安装测试环境&#xff1a; vmware-ubuntu20.04&#xff0c;gcc 4.8.5&#xff0c;ragel-6.10.tar.gz&#xff0c;boost_1_69_0.tar.gz&#xff0c;hyperscan-5.1.0.tar.gz 1.安装ragel&#xff08;必须的依赖包&#xff09;1MB&#xff1a; 下载地址&#xff1a;http://www.…

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

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

msys2+mingw64+ragel安装

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

Ragel State Machine Compiler 的速度测试

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

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

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

嵌入式系统开发流程

一、嵌入式系统开发流程 1、系统需求分析&#xff1a;根据需求&#xff0c;确定设计任务和设计目标&#xff0c;指定设计说明书。 2、体系结构设计&#xff1a;描述系统如何实现所述的功能需求&#xff0c;包括对硬件、软件和执行装置的功能划分以及系统的软件、硬件选型。 …

嵌入式系统开发设计

嵌入式系统开发设计 嵌入式系统设计的主要任务是定义系统的功能、决定系统的架构&#xff0c;并将功能映射到系统实现架构上。系统架构既包括软件系统架构也包括硬件系统架构。 嵌入式系统设计具有以下特点&#xff1a; 软、硬件协同并行开发&#xff1b; 微处理器的类型多种…