danielwinter
danielwinter

Reputation: 331

Integrating PayPal REST API into Laravel using Omnipay - The card parameter is required

I'm using L5 and want to integrate my PayPal purchases into that system. The sandbox is already set up and I can do all my payments using the real PayPal API package, but as I want to try to do it with Omnipay I'm struggling a bit:

When I execute this code:

Route::get('test', function()
{
$gateway = Omnipay::create('PayPal_Rest');
$gateway->setClientId('{my id}');
$gateway->setSecret('{my secret}');
$gateway->setTestMode(true);

$params = array(
    'cancelUrl' => 'http://webshop.app',
    'returnUrl' => 'http://webshop.app/testresp',
    'name'  => 'Your Purchase',
    'description' => 'Your Description',
    'amount' => '15.99',
    'currency' => 'EUR'
);

Session::put('params', $params);
Session::save();

$resp = $gateway->purchase($params)->send();

if ($resp->isSuccessful()) {
    // payment was successful: update database
    print_r($resp);
} elseif ($resp->isRedirect()) {
    // redirect to offsite payment gateway
     $resp->redirect();
} else {
    // payment failed: display message to customer echo
     $resp->getMessage();
}
});

I get this: InvalidRequestException in AbstractRequest.php line 122: The card parameter is required

Seems like I would have to initiate that purchase with credit card information of the client, which I do not want to gather (hence using PayPal in the first place). Is there any way to use that API without usage of a credit card?

I don't like the usage of the Express API as I don't want my PayPal username and password within my code. For several reasons.

Upvotes: 2

Views: 2227

Answers (2)

delatbabel
delatbabel

Reputation: 3681

Check out the following branch of my fork of the omnipay-paypal gateway code: https://github.com/delatbabel/omnipay-paypal/tree/accept-paypal-payments

That includes code that allows you not to pass through a credit card and have PayPal do the payment processing.

I have submitted a PR but it hasn't been merged into the main omnipay-paypal repository yet.

Upvotes: 0

Maximilian Prepl
Maximilian Prepl

Reputation: 412

The Card array field is required. it's not required to insert credit card number, but you will need to provide some information.

From the official docs:

Even off-site gateways make use of the CreditCard object, because often you need to pass customer billing or shipping details through to the gateway.

Upvotes: 1

Related Questions