zencart1.55手把手教你开发stripe支付插件

article/2025/4/20 0:56:44

第一步:在includes/modules/payment目录下创建名称为c_stripe的文件夹,用于存放stripe支付logo

第二步:在同includes/modules/payment目录下创建c_stripe.php文件,这个文件就是用于编写zencart支付插件,代码如下

<?php
//®
/*** @package money order payment module** @package paymentMethod* @copyright Copyright 2003-2010 Zen Cart Development Team* @copyright Portions Copyright 2003 osCommerce* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0* @version GIT: $Id: Author: DrByte  Tue Jan 22 03:36:04 2013 -0500 Modified in v1.5.2 $*/define('MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE', 'true');class c_stripe {var $code, $title, $description, $enabled,$context;// class constructorfunction c_stripe() {global $order;$this->code = 'c_stripe';$this->title = MODULE_PAYMENT_C_STRIPE_TEXT_TITLE;$this->description = MODULE_PAYMENT_C_STRIPE_TEXT_DESCRIPTION;$this->sort_order = MODULE_PAYMENT_C_STRIPE_SORT_ORDER;$this->enabled = ((MODULE_PAYMENT_C_STRIPE_STATUS == 'True') ? true : false);if ((int)MODULE_PAYMENT_C_STRIPE_ORDER_STATUS_ID > 0) {$this->order_status = MODULE_PAYMENT_C_STRIPE_ORDER_STATUS_ID;}if (is_object($order)) $this->update_status();$this->email_footer = MODULE_PAYMENT_C_STRIPE_TEXT_EMAIL_FOOTER;if ($this->enabled && $_SESSION['cart'] && ($_SESSION['cart']->show_total() > intval(MODULE_PAYMENT_C_STRIPE_MAX_AMOUNT) || $_SESSION['cart']->show_total() < intval(MODULE_PAYMENT_C_STRIPE_MIN_AMOUNT))) {$this->enabled = false;}}// class methodsfunction update_status() {global $order, $db ;if ($this->enabled && (int)MODULE_PAYMENT_C_STRIPE_ZONE > 0 && isset($order->billing['country']['id'])) {$check_flag = false;$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_C_STRIPE_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");while (!$check->EOF) {if ($check->fields['zone_id'] < 1) {$check_flag = true;break;} elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {$check_flag = true;break;}$check->MoveNext();}if ($check_flag == false) {$this->enabled = false;}}}function javascript_validation() {return false;}function selection() {global $current_page_base,$template;$m_fieldsArray [] = array ('title' => '','field' =>'','tag' => '' );return array('id' => $this->code,'module' =>'<img src="./includes/modules/payment/c_stripe/stripe.png" style="height: 50px;vertical-align: middle;">','fields' =>$m_fieldsArray);}function pre_confirmation_check(){return false;}function check_checkout_pay() {global $db, $order, $order_totals, $order_total_modules,$messageStack,$currencies;if(isset($_SESSION['order_number_created']))$_SESSION['order_id'] = $_SESSION['order_number_created'];$order_id = $_SESSION['order_id'];date_default_timezone_set(date_default_timezone_get());$currency = $_SESSION['currency'];//due to zen cart bug,we should not do currency exchange with zen cart build in currency class,keep in mind$amount = zen_round($order->info['total'] * $currencies->currencies[$currency]['value'], $currencies->currencies[$currency]['decimal_places']);// 回调URL$strServerUrl = zen_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL');//支付成功后的回调地址$strNotifyUrl = zen_href_link('c_stripe_payment.php', '', 'SSL',false,false,true);$state = $order->customer['state'];$data = array('order_no'=>$order_id,'currency'=>$currency,'success_uri'=>$strServerUrl,'notify_url'=>$strNotifyUrl,'amount'=>$amount,'key' => MODULE_PAYMENT_C_STRIPE_API_USERNAME;);$_SESSION['payment_order'] = $data;zen_redirect(zen_href_link("checkout_stripe"));exit;}function confirmation() {return array('title' => MODULE_PAYMENT_C_STRIPE_TEXT_DESCRIPTION);}function process_button() {$process_button_string="";if(isset($this->orders_id)&&$this->orders_id!=""){$process_button_string .= zen_draw_hidden_field('orders_id', $this->orders_id);  $process_button_string .= zen_draw_hidden_field('redirect_url',$this->redirect_url);  $process_button_string .= zen_draw_hidden_field('fetch_url', $this->fetch_url);  $process_button_string .= zen_draw_hidden_field('callback_url', $this->callback_url);  }return $process_button_string;}function before_process() {return false;}function after_process() {$this->check_checkout_pay();return false;}function get_error() {return false;}function check() {global $db;if (!isset($this->_check)) {$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_C_STRIPE_STATUS'");$this->_check = $check_query->RecordCount();}return $this->_check;}function install() {global $db, $messageStack;$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('打开Stripe支付', 'MODULE_PAYMENT_C_STRIPE_STATUS', 'True', '您要使用Stripe支付方式吗?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('支付签名key', 'MODULE_PAYMENT_C_STRIPE_API_USERNAME', '', '', '6', '0', now())");$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('显示顺序', 'MODULE_PAYMENT_C_STRIPE_SORT_ORDER', '999', '显示顺序:小的显示在前。', '6', '0', now())");$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_C_STRIPE_ORDER_STATUS_ID', '7', '', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Success Order Status', 'MODULE_PAYMENT_C_STRIPE_ORDER_SUCCESS_STATUS_ID', '8', '', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Failure Order Status', 'MODULE_PAYMENT_C_STRIPE_ORDER_FAIL_STATUS_ID', '9', '', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");}function remove() {global $db;$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");}function keys() {return array('MODULE_PAYMENT_C_STRIPE_STATUS','MODULE_PAYMENT_C_STRIPE_API_USERNAME','MODULE_PAYMENT_C_STRIPE_SORT_ORDER','MODULE_PAYMENT_C_STRIPE_ORDER_STATUS_ID','MODULE_PAYMENT_C_STRIPE_ORDER_SUCCESS_STATUS_ID','MODULE_PAYMENT_C_STRIPE_ORDER_FAIL_STATUS_ID');}}

以上就是主要的支付代码文件了

第三步:在includes/languages/english/modules/payment下创建c_stripe.php,这个文件主要是用于后台支付插件的标题等说明

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: moneyorder.php 1969 2005-09-13 06:57:21Z drbyte $
//define('MODULE_PAYMENT_C_STRIPE_TEXT_TITLE', '支付插件教程');define('MODULE_PAYMENT_C_STRIPE_TEXT_DESCRIPTION', '');define('MODULE_PAYMENT_C_STRIPE_TEXT_EMAIL_FOOTER', '');define('MODULE_PAYMENT_C_STRIPE_PURCHASE_DESCRIPTION_TITLE', 'All the items in your shopping basket (see details in the store and on your store receipt).');?>

如果你有多个国家,同样复制修改对应的国家语言 字段即可


第四步:在includes\modules\pages创建checkout_stripe\header_php.php

<?php
/*** checkout_payresult header_php.php** @package page* @copyright Copyright 2003-2007 Zen Cart Development Team* @copyright Portions Copyright 2003 osCommerce* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0*/if (isset($_SESSION['payment_order']) && !empty($_SESSION['payment_order']))
{$paymentdata = $_SESSION['payment_order'];
}$breadcrumb->add("Checkout Stripe");
?>

第五步:在目录includes\templates\template_default\templates创建tpl_checkout_stripe_default.php支付页面

<php
$paymentdata = paymentdata;
?>
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8" /><title>Accept a payment</title><meta name="description" content="A demo of a payment on Stripe" /><meta name="viewport" content="width=device-width, initial-scale=1" /><link rel="stylesheet" href="checkout.css" /><script src="https://js.stripe.com/v3/"></script><script src="checkout.js" defer></script></head><body><!-- Display a payment form --><form id="payment-form">
<input type="hidden" value="<?php eccho $paymentdata['金额']"><div id="payment-element"><!--Stripe.js injects the Payment Element--></div><button id="submit"><div class="spinner hidden" id="spinner"></div><span id="button-text">Pay now</span></button><div id="payment-message" class="hidden"></div></form></body>
</html>

备注:页面tpl_checkout_stripe_default.php接收到$paymentdata数据,使用<input type="hidden" value="<?php eccho $paymentdata['金额']">

请根据stripe自定义支付修改自己的php提交地址,直接复制stripe代码过来修改js对应的提交php文件就可以了。

 

 

 如有不清楚的地方记得联系我


http://chatgpt.dhexx.cn/article/0yxWgNQN.shtml

相关文章

JAVA接入STRIPE支付教程(测试环境),STRIPE支付的调用以及STRIPE WEBHOOK回调

一、环境准备 1.注册 2.密钥 3.WEBHOOK回调 二、核心代码 1.配置API.key以及webhook.key 2.支付demo 3.WEBHOOK回调 一、环境准备 1.注册 STRIPE官网自行注册账号 2.两个重要的密钥 首先在STRIPE官网注册账号之后进入首页&#xff0c;点击API密钥&#xff0c;查看账号对应的…

前端对接stripe支付,创建测试session_is

第一次搞 stripe支付&#xff0c;国外的文档全英文 接stripe支付&#xff0c;根据官方文档&#xff0c;首先就是先跟服务端交互&#xff0c;创建session会话&#xff0c;获取id&#xff0c;当服务端不做这个功能时&#xff0c;就需要前端去掉stripe最底层的api&#xff0c;拿到…

Stripe支付简介和前端js调用

最近公司正在做一个国际版APP&#xff0c;涉及到海外支付&#xff0c;调研过Paypal、Skrill、BrainTree、Stripe&#xff08;可参考海外移动支付方案对比&#xff09;&#xff0c;最终 选择了Stripe支付。Stripe特点如下&#xff1a; 收费规则简单透明&#xff0c;手续费就是收…

laravel 对接stripe支付

参考文档 &#xff1a; stripe文档 stripe/stripe-php stripe api 文档 目录 一 获取关键参数二 安装Stripe库三 代码示例 一 获取关键参数 SCRIPE_SECRET_KEY &#xff08;调用api秘钥&#xff09; NOTIFY_SIGN (签名 支付回调使用) 二 安装Stripe库 # Install the PHP libr…

Stripe支付配置

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

php实现Stripe支付 | ecshop stripe支付

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

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.…