php-omnipayHow do I use PHP Omnipay to verify a payment?
Using PHP Omnipay to verify a payment requires two steps:
- Initialize the payment gateway:
require_once('vendor/autoload.php');
$gateway = Omnipay\Omnipay::create('PayPal_Express');
$gateway->setUsername('[email protected]');
$gateway->setPassword('1234567890');
$gateway->setSignature('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$gateway->setTestMode(true);
- Verify the payment:
$response = $gateway->completePurchase([
'transactionReference' => '1234567890',
'amount' => '10.00',
'currency' => 'USD',
])->send();
if ($response->isSuccessful()) {
echo "Payment is verified!";
} else {
echo "Payment is not verified!";
}
require_once('vendor/autoload.php')
: This line includes the Omnipay library.$gateway = Omnipay\Omnipay::create('PayPal_Express')
: This line creates a new instance of the PayPal Express gateway.$gateway->setUsername('[email protected]')
: This line sets the username of the gateway.$gateway->setPassword('1234567890')
: This line sets the password of the gateway.$gateway->setSignature('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
: This line sets the signature of the gateway.$gateway->setTestMode(true)
: This line sets the gateway to test mode.$response = $gateway->completePurchase([])->send()
: This line sends the payment verification request to the gateway.if ($response->isSuccessful())
: This line checks if the payment is successful.
Helpful links
More of Php Omnipay
- How can I use PHP Omnipay to process Yandex payments?
- How do I use PHP Omnipay Wallet to make payments?
- How do I use the PHP Omnipay Validator?
- How do I update my Omnipay library in PHP?
- How do I use Omnipay with PHP?
- How do I set up and use the Omnipay PHP package?
- How can I use PHP Omnipay to access metadata?
- How can I use Omnipay Qiwi to process payments in my PHP application?
- How can I use Omnipay with PHP to get the value of a payment?
See more codes...