What is not clear on the documentation for the Omnipay package?
Create a payment using laravel
Hello, i am quite new to laravel, and even more to shooping online.
The problem is that I want to create a way to pay the diferents plans I've got in my website, looking forward paying with paypal, and here's what i found:
OMNIPAY: Using composer I've installed it' and the problem is that i don't know how is it working, because i found little documentation about it. You can see what I've got here: http://puu.sh/hjhEA/8da8839504.png
The problem with the current code is that it does nothing, (I don't understand how it works tho..)
if anybody can help me with this, I would aprreciate it.
Is there any way to pay with paypal and the ncheck if the payment was successful using Laravel 5?
I found a paypal library but it's for laravel 4 :(
Any help is apreciated!
I was not using this specific laravel package, but still, what should i put in the function, look my image
@ConsoleTVs I’m looking through your code and you’re doing a lot of find queries. The top four lines are all find queries, which could be condensed to just two:
$settings = Settings::find(1);
$plan = Plan::whereName($name)->first();
if ($plan->cost == 0) {
Session::flash('msg', $plan->name.' is a free upgrade.');
//
}
As for why your payment isn’t working, when I’ve worked with PayPal Express I’ve had to specify a username, password and a signature. I have some code on a live site that looks like this for capturing payment via PayPal:
// Create order record in database here
$gateway = Omnipay::create($payment_method);
$gateway->setUsername(config('services.paypal.username'));
$gateway->setPassword(config('services.paypal.password'));
$gateway->setSignature(config('services.paypal.signature'));
$gateway->setTestMode(config('services.paypal.test_mode'));
$order_details = [
'amount' => $item->price,
'brandName' => $site_name,
'cancelUrl' => url('order/cancel'),
'currency' => 'GBP',
'description' => $item->description,
'returnUrl' => url('payment/callback/'.$order->id),
];
$response = $gateway->purchase($order_details)->send();
if ($response->isRedirect()) {
$response->redirect();
} else {
throw new Exception($response->getMessage());
}
I create the order in my database first with its status set to unpaid. I then listen for a callback from PayPal to update the record to paid when and only when the user has successfully made the payment in full via PayPal.
You also don’t need the isSuccessful() condition as PayPal is an off-site payment gateway and works via redirects.
Hope this helps.
Let me try it, the fact is the following:
Will this redirect the user to paypal payment and once done will come back to this function in order to check the respone?
The function i got this code is is using GET method, so when visited again, will try to execute the code again.
I've managed to install the laravel 5 omnipay package, and now I've got this:
echo "And now, pay!<br>";
Omnipay::setGateway('PayPal_Express');
$response = Omnipay::purchase([
'amount' => '100.00',
'card' => $cardInput
])->send();
dd($response->getMessage());
The configuration file created (config/laravel-omnipay.php):
<?php
return [
// The default gateway to use
'default' => 'paypal',
// Add in each gateway here
'gateways' => [
'paypal' => [
'driver' => 'PayPal_Express',
'options' => [
'solutionType' => '',
'landingPage' => '',
'headerImageUrl' => ''
]
]
]
];
I know that i should add the signature as well, but where should i add all this data? i mean the config file doesn't have a place for it!
And btw, will this code be redirecting the user or i should do something?
Sorry guys but I'm quite lost, I really apreciate your help!
Hi @ConsoleTVs. Did you finally figure it out? I installed the gateway and the https://github.com/ignited/laravel-omnipay package but I'm getting an error when I invoke the Omnipay::setGateway. I've created a dummy test page that looks as follows:
public function testPayment (){
Omnipay::setGateway( 'Redsys' );
//// Omnipay::setGateway('Redsys');
$buyerInfo = [
'firstName' => 'test user',
];
$purchase = Omnipay::purchase([
'amount' => '10.00', // decimals mandatory
'transactionId' => '1234aaaaaaaa', // xxxxAAAAAAAA (4 numbers, 8 alphanumerics)
'currency' => '978', // 978 >> Eur
'description' => 'ADSL Prueba',
'notifyUrl' => '/payment/redsys/pay', // redsys will send here a POST message
'returnUrl' => '/payment/redsys/payment-success', // buyer will be redirected here if purchase confirmed
'cancelUrl' => '/payment/redsys/payment-failure', // buyer will be redirected here if purchase cancelled or rejected
'card' => $buyerInfo
]);
$response = $purchase->send();
if ($response->isSuccessful())
{
// payment was successful: update database
// print_r($response);
return Redirect::route('redsys.payment.success');
}
// elseif ($response->isRedirect())
// {
// // redirect to offsite payment gateway
// // this is the usual way of doing this
// $response->redirect();
// }
else
{
// payment failed: display message to customer
// echo $response->getMessage();
return Redirect::route('redsys.payment.failure');
}
}
I'm getting the following error: 'Omnipay\Common\GatewayFactory' does not have a method 'setGateway' I've imported the Omnipage namespace and set both the facades and providers. Frankly, I'm out of ideas.
I would greatly appreciate if anybody could send me in the right direction.
Thanks in advance
I was having the same problem. Just add a use statement:
use Ignited\LaravelOmnipay\Facades\OmnipayFacade as Omnipay;
Please or to participate in this conversation.