Stan Stan - 1 month ago 4
PHP Question

Implementing Payment Gataway in Laravel based shop

I need a little help with implementing payment getaway in Laravel shop.
Payment I use is and I can't understand how to take needed information. So I have set the files database table, database connection and all.. Now I'm trying to redirect user to

page after order form is submitted. This is my
orderSubmit function

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')) {
$shipping['title'] = 'Normal Delivery';
$shipping['price'] = 0;

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

$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');

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.');

and this is payment.php

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


$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";

$options = array(
"public_key" => $public_key, // your public key from
"private_key" => $private_key, // your private key from
"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";
{ // 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
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);

My question is how to take the correct info in the payment.php? How to take userID, userFormat, orderID and so on?


First of all, I would suggest you use Laravel as the framework it is intended for. In Laravel you define controllers to handle your http-requests. Make a new PaymentController and put the code from payment.php into this controller. Then make a route to that controller-method.

Also put your configuration settings in Laravels config-folder.

And the require_once( "../cryptobox.class.php" ); can be replaced by a dependency injection in your controllers constructor.

Now back to your question.

$userID is where you put your registered Laravel user ID. (If you dont have any registered users, leave it blank). Why you should put your user's id in this variable? -It helps to keep track of which users have done which payments. You can later save this information in your database if you want to keep track of payment history.

$orderID This is where you put your internal order id. Why should you use an internal order id? -Again its to keep track of which purchases of which products have been done by which users. You can store your order-id in your database together with user-id and product-id to get a purchase history log.

$userFormat This is how you wish to store your user information, session, cookie, etc. Because when the purchase is executed, the payment gateway needs a way to access this information, and therefor it must be stored in the session or in a cookie.