skip to Main Content

I’m trying to integrate Paypal as the payment gateway in my Laravel 5.8 website. In order to do so I’m using the Laravel-Omnipay package which offers Omnipay integration into Laravel.

As for my Paypal business account, I’ve set up my credentials. Using the paypal sandbox with the following code works:

Route::get('paypal', function() {
    $gateway = Omnipay::create('PayPal_Rest');

    $gateway->initialize(array(
        'clientId' => 'MySandboxClientId',
        'secret'   => 'MySandboxSecret',
        'testMode' => true,
    ));
    $card = new CreditCard(array(
        'firstName' => 'first name',
        'lastName' => 'last name',
        'number' => '5498876202508868',
        'cvv' => '123',
        'expiryMonth'           => '09',
        'expiryYear'            => '2024',
        'billingAddress1'       => '1 Scrubby Creek Road',
        'billingCountry'        => 'AU',
        'billingCity'           => 'Scrubby Creek',
        'billingPostcode'       => '4999',
        'billingState'          => 'QLD',
    ));
    try {
        $transaction = $gateway->purchase(array(
            'amount'        => '10.00',
            'currency'      => 'USD',
            'description'   => 'This is a test purchase transaction.',
            'card'          => $card,
        ));
        $response = $transaction->send();
        $data = $response->getData();
        dd($data);
        echo "Gateway purchase response data == " . print_r($data, true) . "n";

        if ($response->isSuccessful()) {
            echo "Purchase transaction was successful!n";
        }
    } catch (Exception $e) {
        echo "Exception caught while attempting authorize.n";
        echo "Exception type == " . get_class($e) . "n";
        echo "Message == " . $e->getMessage() . "n";
    }
});

However, when I try to pass to a live payment using my own credit card. I can an Unauthorized payment. error. The code I’m using is the same as above, I’m just replacing the clientId and secret with my live sandbox credentials.

How can I make a live call to the REST Api. I need to make a $1 transaction so I can test whether the card is valid or not.

2

Answers


  1. As per paypal documentation ,
    unauthorized payment error occurs when ,

    Any payment made from a debit or credit card, bank account or PayPal account without the account owner’s permission is an unauthorized payment.

    When PayPal believes that a payment is unauthorized, we place a hold on it. Money can’t be withdrawn until we determine if the payment is authorized.

    If the payment is unauthorized, the money is returned to the sender’s account. Sellers who meet the eligibility guidelines unde PayPal Seller Protection are protected.

    So it might be the issue with credit card. Try with another credit card or follow the instructions which is mentioned here .
    Unauthorized error paypal

    Login or Signup to reply.
  2. Just set ‘testMode’ => true, to ‘testMode’ => false, that’s all

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search