"Invalid request - see details" in Paypal PHP Integration Omnipay

I have integrated this Paypal Payment in my php application with Omnipay
in myindex.php
I have done this
<form action="process.php" method="POST">
<button type="submit">Pay with Paypal</button>
</form>
In myprocess.php
I have done this
<?php
require_once 'config.php';
try {
$response = $gateway->purchase(array(
'amount' => 100,
'currency' => PAYPAL_CURRENCY,
'returnUrl' => PAYPAL_RETURN_URL,
'cancelUrl' => PAYPAL_CANCEL_URL,
))->send();
if ($response->isRedirect()) {
$response->redirect(); // this will automatically forward the customer
} else {
// not successful
dd($response->getMessage());
}
} catch(Exception $e) {
dd($e);
}
function dd($content)
{
echo "<pre>";
var_dump($content);
echo "</pre>";
}
In myconfig.php
I have done this
<?php
require_once "vendor/autoload.php";
use Omnipay\Omnipay;
define('CLIENT_ID', 'my-client-id');
define('CLIENT_SECRET', 'my-secret-id');
define('PAYPAL_RETURN_URL', 'localhost/paypalwp/success.php');
define('PAYPAL_CANCEL_URL', 'localhost/paypalwp/cancel.php');
define('PAYPAL_CURRENCY', 'USD'); // set your currency here
$gateway = Omnipay::create('PayPal_Rest');
$gateway->setClientId(CLIENT_ID);
$gateway->setSecret(CLIENT_SECRET);
$gateway->setTestMode(true); //set it to 'false' when go live
And in mysuccess.php
I have done this
<?php
require_once 'config.php';
// Once the transaction has been approved, we need to complete it.
if (array_key_exists('paymentId', $_GET) && array_key_exists('PayerID', $_GET)) {
$transaction = $gateway->completePurchase(array(
'payer_id' => $_GET['PayerID'],
'transactionReference' => $_GET['paymentId'],
));
$response = $transaction->send();
if ($response->isSuccessful()) {
// The customer has successfully paid.
$arr_body = $response->getData();
$payment_id = $arr_body['id'];
$payer_id = $arr_body['payer']['payer_info']['payer_id'];
$payer_email = $arr_body['payer']['payer_info']['email'];
$amount = $arr_body['transactions'][0]['amount']['total'];
$currency = PAYPAL_CURRENCY;
$payment_status = $arr_body['state'];
echo "Payment is successful. Your transaction id is: ". $payment_id;
} else {
echo $response->getMessage();
}
} else {
echo 'Transaction is declined';
}
and incancel.php
I have simple html layout which says user has cancel the payment
But when I try this code it gives me this error"Invalid request - see details"
Any idea why this ?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: 403 this action is unauthorized.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.