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 do I use the PHP Omnipay Validator?
- How can I use PHP Omnipay to access metadata?
- How do I set up and use the Omnipay PHP package?
- How do I use PHP Omnipay Wallet to make payments?
- How can I use Omnipay in PHP?
- How do I update my Omnipay library in PHP?
- How can I use PHP Omnipay to process a billing transaction?
- How do I use Omnipay with PHP to process zero-dollar transactions?
- How can I use Omnipay with PHP to get the value of a payment?
See more codes...