Omnipay, paypal REST with laravel 5

The answer I get in dd($finalResponse);is:

RestResponse {#298 ▼
  #statusCode: 400
  #request: RestCompletePurchaseRequest {#300 ▶}
  #data: array:4 [▼
    "name" => "PAYMENT_NOT_APPROVED_FOR_EXECUTION"
    "message" => "Payer has not approved payment"
    "information_link" => "https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_NOT_APPROVED_FOR_EXECUTION"
    "debug_id" => "5471589613718"
  ]
}

Here is the code.

$gateway = Omnipay::create('PayPal_Rest');

    // Initialise the gateway
    $gateway->initialize(array(
       'clientId' => env('PAYMENT_SANDBOX_PAYPAL_CLIENTID'),
       'secret'   => env('PAYMENT_SANDBOX_PAYPAL_SECRET'),
       'testMode' => true, // Or false when you are ready for live transactions
    ));

    // Do an authorisation transaction on the gateway
    $transaction = $gateway->authorize(array(
        'returnUrl'=> env('PAYMENT_SANDBOX_PAYPAL_URL'),
        'cancelUrl' => 'http://localhost:8000/cancel',
       'amount'        => '10.00',
       'currency'      => 'AUD',
       'description'   => 'This is a test authorize transaction.',
       // 'card'          => $card,
    ));

    $response = $transaction->send();
    if ($response->isSuccessful()) {
       // Find the authorization ID
       $authResponse = $response->getTransactionReference();
       echo "Authorize transaction was successful!\n".$authResponse;
    }else{
        echo "Failed to auth transaction";
        dd($response);
    }

    // Once the transaction has been approved, we need to complete it.
    $transaction = $gateway->completePurchase(array(
        'payerId'             => $request->PayerID,
        'transactionReference' => $authResponse            
    ));

    $finalResponse = $transaction->send();

    dd($finalResponse);

    if ($finalResponse->getData()) {
       echo "Transaction was successful!\n";
       // Find the authorization ID
       $results = $finalResponse->getTransactionReference();
        dd($results);
    }else{
        dd($finalResponse->getData());
    }

After logging in as a payer and completing the purchase, what else should the payer approve and how?

+4
source share
1 answer

No, you misunderstand the PayPal payment process. Here is the correct thread:

  • Omnipay:: create(), $gateway- > initialize() $gateway- > authorize() , , . returnUrl URL- , cancelUrl. , http://localhost:8000/return ( - URL).

  • $gateway- > authorize() RedirectResponse. :

//

$transaction = $gateway->authorize(array(
    'returnUrl'=> env('PAYMENT_SANDBOX_PAYPAL_URL'),
    'cancelUrl' => 'http://localhost:8000/cancel',
    'amount'        => '10.00',
    'currency'      => 'AUD',
    'description'   => 'This is a test authorize transaction.',
    // 'card'          => $card,
));

$response = $transaction->send();
if ($response->isRedirect()) {
    // Yes it a redirect.  Redirect the customer to this URL:
    $redirectUrl = $response->getRedirectUrl();
}

. - PayPal, , PayPal, , , , .

, , , PayPal -, redirectUrl, authorize(). . completeAuthorize, , :

// Once the transaction has been approved, we need to complete it.
$transaction = $gateway->completePurchase(array(
    'payerId'             => $request->PayerID,
    'transactionReference' => $authResponse            
));

$finalResponse = $transaction->send();

dd($finalResponse);

if ($finalResponse->getData()) {
   echo "Transaction was successful!\n";
   // Find the authorization ID
   $results = $finalResponse->getTransactionReference();
    dd($results);
}else{
    dd($finalResponse->getData());
}

, returnUrl.

cancelUrl, PayPal URL- cancelUrl -.

, , - PayPal, url. - , - , , " " PayPal . - omnipay-paypal fetchPurchase() listPurchase().

+12

Source: https://habr.com/ru/post/1613276/


All Articles