How to change programmatically Laravel Omnipay object? - laravel

Currently, I am handling stripe payments with Omnipay's Stripe library. Similar with the example below:
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey("sk_test_xHGgkZtGOlTwxi4d8GYOHifZ");
$formData = array('number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2030', 'cvv' => '123');
$response = $gateway->purchase(array('amount' => '10.00', 'currency' => 'USD', 'card' => $formData))->send();
However, there are too much different payment gateways. Let's assume, I've both Paypal and Stripe packages of omnipay. How can I handle the omnipay package that selected as a default on db. I don't know what to do. Ofcourse, You could say simply use if and else. But, it's not a good in practice. What sticks my mind and bother me is implementing this idea with a generic way with the S.O.L.I.D. principles in Laravel.

Related

Using Payment-Element in Stripe and Laravel

We have everything working in Laravel using Stripes card-element. We want to start using the new payment-element. We are currently using the setup intent.
Following the guide: https://stripe.com/docs/payments/payment-element/migration
Stripe says to add payment methods like so:
$intent = \Stripe\SetupIntent::create([
'customer' => $customer->id,
'payment_method_types' => ['card', 'bancontact', 'ideal'],
]);
In Laravel we currently have it setup like so:
return view('payment.payment')->with([
'services' => $services,
'intent' => $user->createSetupIntent()
]);
How do we pass payment_method_types to the Laravel cashier's createSetupIntent() method?

Laravel - Payone

Is there an easy wrapper for the payone(https://www.payone.de/) API for Laravel? I only found one company who sells a package but nothing that is open source. I would appreciate any help.
You should consider Omnipay: http://omnipay.thephpleague.com/
Because:
It is gateway independent.
It is framework independent. It works well with Laravel but also Symfony, Yii, etc.
There is an Omnipay plugin for PayOne: https://github.com/academe/OmniPay-Payone
The code to make a purchase via Omnipay is pretty much the same regardless of the gateway. Here is some sample code that should work, although you should check the details of the Payone classes for other information that you need to send. The Payone gateway can work in multiple different ways depending on how your account is set up.
$gateway = Omnipay::create('Payone_ShopServer');
$card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
// ... etc
));
$transaction = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Purchase transaction was successful!\n";
}
// At this point you should get $response->getTransactionReference()
// and store that or something similar.

CI Merchant no output

I am trying to use CI Merchant library for codeignator
here is my code:
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$settings = array(
'username' => 'api.sandbox.paypal.com',
'password' => 'AQHaXxDW3dlKDRDJ7lDtGr4w8-reNNfvPFUKmEr9npMzYjZ2WIbfqqI3VL2C',
'signature' => 'EMbUfhBCqBZw8hhH6q8VZT_53-xwoOs6_lotS68I7qrY5iyHPLgDitrsAZj5',
'test_mode' => true);
$this->merchant->initialize($settings);
$params = array(
'amount' => 100.00,
'currency' => 'USD',
'return_url' => 'https://www.example.com/checkout/payment_return/123',
'cancel_url' => 'https://www.example.com/checkout');
$response = $this->merchant->purchase($params);
echo '<pre>';
print_r($response);
echo '</pre>';
but when I run it local here is result:
Merchant_response Object
(
[_status:protected] => failed
[_message:protected] => error setting certificate verify locations:
CAfile: C:\xampp\htdocs\egyptianornaments\application\config/cacert.pem
CApath: none
[_reference:protected] =>
[_data:protected] =>
[_redirect_url:protected] =>
[_redirect_method:protected] => GET
[_redirect_message:protected] =>
[_redirect_data:protected] =>
)
and when I run on the server I get a blank page
so what I am doing wrong?
Looks like your code is setup to use a certificate instead of the signature method, but your servers don't have the SSL cert installed and configured to work with PayPal, which is really sort of a pain to deal with anyway. I would recommend switching to the signature method and then you won't have to mess with that at all.
I'm not familiar with the library you're using, but there must be some way to set that. You might also want to take a look at my own CodeIgniter library for PayPal that is pretty popular.
I've actually stopped maintenance of that CI specific library, though, because I now have my general PHP library for PayPal updated for PHP 5.3+ and working with Composer / Packagist, which allow you to use it in CodeIgniter or any other framework.
As of today, the CI specific library isn't far behind, but again, I'm not updating it anymore. I'm only maintaining the general version now since it works everywhere.
Anyway, it makes every PayPal API call very simple for you.

Paypal API for codeigniter

I need a paypal library for codeigniter (without redirecting to paypal site), I used angell eye paypal library but it had some issues.
If you have any suggestion which library should i use but i dont want to redirect to paypal site. I have Username, password and signature.
this is my code
$params = array(
'amount' => 100.00,
'currency' => 'USD',
'return_url' => 'https://www.example.com/checkout/payment_return/123',
'cancel_url' => 'https://www.example.com/checkout');
$this->load->library('merchant');
$this->merchant->load('paypal_pro');
$this->load->helper('language');
$settings = array(
'username' => 'sandbo_1215254764_biz_api1.angelleye.com',
'password' => '1215254774',
'signature' => 'AiKZhEEPLJjSIccz.2M.tbyW5YFwAb6E3l6my.pY9br1z2qxKx96W18v',
'test_mode' => true);
$this->merchant->initialize($settings);
$response = $this->merchant->purchase_return($params);
print"<pre>";
print_r($response);die;
Thank You
Try CI-Merchant payments API
In that you need to use PayPal Website Payments Pro
EDIT:
$this->load->library('merchant');
$this->merchant->load('paypal_pro');
Express check out will take you to Paypal site for payment. Paypal pro will process payments in your server.
** Make sure you are running the code in test/production server(public accessible) but not local machine

receive more response data in ci-merchant library codeigniter

How can I receive more response data in the ci-merchant codeigniter library ?
I am using the Paypal Express checkout payment method.
And I am passing the following parameters:
$params = array(
'amount' => 100.00,
'currency' => 'USD',
'return_url' => my return url,
'cancel_url' => my cancel url );
Right now am getting just the following response
Merchant_paypal_api_response Object
(
[_status:protected] => complete
[_message:protected] =>
[_reference:protected] => 1K088384XU0947545
[_data:protected] =>
[_redirect_url:protected] =>
[_redirect_method:protected] => GET
[_redirect_message:protected] =>
[_redirect_data:protected] =>
)
How can I get the data like paypal id, shipping address, item name and other stuff that paypal returns in the DoExpressCheckoutPayment response ?
Actually, that info wouldn't come back in the DECP response. It would come back in GetExpressCheckoutDetails.
Your library should provide some way to see the RAW API requests and responses. If it's not parsing out all of the details for you you'll need to do that on your own.
This isn't exactly an answer to your question, but you should try using Omnipay instead. Omnipay is basically CI-Merchant V2 (I'm the author of both libraries).
Omnipay lets you have direct access to the raw response. E.g. you would do something like this:
$params = array( 'amount' => 1000, 'currency' => 'USD', 'returnUrl' => 'my return url', 'cancelUrl' => 'my cancel url' );
$response = $gateway->completePurchase($params)->send();
$reference = $response->getTransactionReference(); // paypal transaction id
$data = $response->getData(); // this is the raw response object

Resources