gpt4 book ai didi

php - 在基于 Laravel 的商店中实现支付网关

转载 作者:行者123 更新时间:2023-12-05 07:49:10 25 4
gpt4 key购买 nike

我需要一些帮助来实现 Laravel 商店中的支付逃逸。我使用的付款方式是 https://gourl.io/而且我不明白如何获取所需的信息。所以我已经设置了文件数据库表、数据库连接等等。现在我试图在提交订单后将用户重定向到 payment.php 页面。这是我的 CartController.php orderSubmit 函数

public function orderSubmit() {
$cart = Session::get(self::CART_SESSION_KEY, array());
if (count($cart) < 1) {
return Redirect::to('/');
}

$validatorRules = array(
'captcha' => 'required|captcha',
'shipping_address' => 'required|min:10',
'shipping_method' => 'required|in:' . implode(',', [Settings::SETTINGS_SHIPPING_NORMAL, Settings::SETTINGS_SHIPPING_EXPRESS])
);

Input::merge(array_map('trim', Input::all()));
$validator = Validator::make(Input::all(), $validatorRules);

if ($validator->fails()) {
return Redirect::to('/cart/order?_token=' . csrf_token())->withErrors($validator->errors())->withInput(Input::except(['captcha']));
}

$shipping = array(
'quantity' => 1,
'image' => '/img/noimage.png',
'description' => '',
'title' => 'FIX ME', // this should never occur,
'price' => 100000 // this should never occur
);
switch (Input::get('shipping_method')) {
case Settings::SETTINGS_SHIPPING_NORMAL:
$shipping['title'] = 'Normal Delivery';
$shipping['price'] = 0;
break;

case Settings::SETTINGS_SHIPPING_EXPRESS:
$shipping['title'] = sprintf('Express Delivery - $%.2f', Settings::getOption('express_shipping_cost'));
$shipping['price'] = doubleval(Settings::getOption('express_shipping_cost'));
break;
}

$cart['shipping'] = $shipping;
$order = new Order();
$order->user_id = self::$user->user_id;
$order->data = json_encode($cart);
$order->address = Input::get('shipping_address');
$order->pgp_key = Input::get('gpgkey');
$order->info = Input::get('additional_info');
$order->save();

Session::put(self::CART_SESSION_KEY, array());
return Redirect::to('payment.php')->with('message_success', 'Order created! We will contact you shortly to confirm your order and payment details.');
}

这是payment.php

    require_once( "../cryptobox.class.php" );

/**** CONFIGURATION VARIABLES ****/

$userID = ""; // place your registered userID or md5(userID) here (user1, user7, uo43DC, etc).
// you don't need to use userID for unregistered website visitors
// if userID is empty, system will autogenerate userID and save in cookies
$userFormat = ""; // save userID in cookies (or you can use IPADDRESS, SESSION)
$orderID = "";
$amountUSD = 20;
$period = "NOEXPIRY";
$def_language = "en";
$public_key = "mypublickey";
$private_key = "myprivatekey";



/** PAYMENT BOX **/
$options = array(
"public_key" => $public_key, // your public key from gourl.io
"private_key" => $private_key, // your private key from gourl.io
"webdev_key" => "", // optional, gourl affiliate key
"orderID" => $orderID, // order id or product name
"userID" => $userID, // unique identifier for every user
"userFormat" => $userFormat, // save userID in COOKIE, IPADDRESS or SESSION
"amount" => 0, // product price in coins OR in USD below
"amountUSD" => $amountUSD, // we use product price in USD
"period" => $period, // payment valid period
"language" => $def_language // text on EN - english, FR - french, etc
);

// Initialise Payment Class
$box = new Cryptobox ($options);

// coin name
$coinName = $box->coin_name();

// Successful Cryptocoin Payment received
if ($box->is_paid())
{
if (!$box->is_confirmed()) {
$message = "Thank you for payment (payment #".$box->payment_id()."). Awaiting transaction/payment confirmation";
}
else
{ // payment confirmed (6+ confirmations)

// one time action
if (!$box->is_processed())
{
// One time action after payment has been made/confirmed

$message = "Thank you for order (order #".$orderID.", payment #".$box->payment_id()."). We will send soon";

// Set Payment Status to Processed
$box->set_status_processed();
}
else $message = "Thank you. Your order is in process"; // General message
}
}
else $message = "This invoice has not been paid yet";

$languages_list = display_language_box($def_language);

我的问题是如何在 payment.php 中获取正确的信息?如何取userID、userFormat、orderID等?

最佳答案

首先,我建议您使用 Laravel 作为它的目标框架。在 Laravel 中,您定义 Controller 来处理您的 http 请求。创建一个新的 PaymentController 并将 payment.php 中的代码放入该 Controller 中。然后创建到该 Controller 方法的路由。

同时将您的配置设置放在 Laravels 配置文件夹中。

并且 require_once( "../cryptobox.class.php"); 可以替换为 Controller 构造函数中的依赖注入(inject)。

现在回到你的问题。

$userID 是您放置注册的 Laravel 用户 ID 的地方。 (如果您没有任何注册用户,请留空)。为什么要将用户的 ID 放入此变量中? - 它有助于跟踪哪些用户完成了哪些付款。如果您想跟踪付款历史记录,您可以稍后将此信息保存在您的数据库中。

$orderID 这是您放置内部订单 ID 的地方。为什么要使用内部订单 ID? -再次跟踪哪些用户购买了哪些产品。您可以将订单 ID 与用户 ID 和产品 ID 一起存储在数据库中,以获取购买历史记录。

$userFormat 这是您希望存储用户信息、 session 、cookie 等的方式。因为在执行购买时,支付网关需要一种方法来访问这些信息,因此必须存储在 session 或 cookie 中。

关于php - 在基于 Laravel 的商店中实现支付网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37748681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com