第一步:在includes/modules/payment目录下创建名称为c_stripe的文件夹,用于存放stripe支付logo
第二步:在同includes/modules/payment目录下创建c_stripe.php文件,这个文件就是用于编写zencart支付插件,代码如下
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 methods
function 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' =>'',
'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,这个文件主要是用于后台支付插件的标题等说明
如果你有多个国家,同样复制修改对应的国家语言 字段即可
第四步:在includes\modules\pages创建checkout_stripe\header_php.php
add("Checkout Stripe");
?>
第五步:在目录includes\templates\template_default\templates创建tpl_checkout_stripe_default.php支付页面
Accept a payment
备注:页面tpl_checkout_stripe_default.php接收到$paymentdata数据,使用
请根据stripe自定义支付修改自己的php提交地址,直接复制stripe代码过来修改js对应的提交php文件就可以了。
如有不清楚的地方记得联系我