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

3

我需要在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等信息?

2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
0
首先,我建议您使用 Laravel 作为框架。在 Laravel 中,您可以定义控制器来处理 HTTP 请求。创建一个新的 PaymentController 并将 payment.php 中的代码放入此控制器中。然后创建一个路由到该控制器方法。 同时,将配置设置放在 Laravel 的 config 文件夹中。 require_once("../cryptobox.class.php") 可以在控制器构造函数中进行依赖注入。 现在回到您的问题。 $userID 是您放置已注册 Laravel 用户 ID 的地方(如果您没有任何已注册用户,则将其留空)。为什么要将用户 ID 放在此变量中?这有助于跟踪哪些用户完成了哪些付款。如果您想要跟踪付款历史记录,稍后可以将此信息保存在数据库中。 $orderID 这是您放置内部订单 ID 的地方。为什么要使用内部订单 ID?同样,这是为了跟踪哪些用户购买了哪些产品。您可以将订单 ID 存储在数据库中,与用户 ID 和产品 ID 一起获取购买历史记录。

$userFormat是你希望存储用户信息、会话、cookie等的方式。因为当购买执行时,支付网关需要访问这些信息,所以它必须存储在会话或者cookie中。


您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - user5035451
MethodNotAllowedHttpException通常出现在您尝试使用错误的HTTP动词访问方法时。例如,如果您尝试使用HTTP-POST调用定义为GET的路由。 - henrik
现在我得到了一个异常:exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /var/www/site/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:148。我的路由是 Route::post('/cart/payment', ['uses' => 'PaymentController@paymentView', 'before' => 'auth|csrf']); 并且正确地重定向到 /cart/payment - user5035451
1
这意味着您正在尝试访问在routes.php文件中未指定的URL。 - henrik

0

如果您使用会话来管理用户,则可以使用$_SESSION['$value']


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,