php-omnipayHow can I use Omnipay with PHP to get the value of a payment?
Omnipay is a payment processing library for PHP that can be used to get the value of a payment. It provides a unified API across many payment gateways, so the same code can be used to process payments from different providers.
Example code for getting the value of a payment using Omnipay:
// Create a gateway for the PayPal Express Checkout
// (routes to GatewayFactory.php)
$gateway = Omnipay::create('PayPal_Express');
// Initialize the gateway
$gateway->initialize(array(
'username' => '[email protected]',
'password' => 'password',
'signature' => 'signature',
'testMode' => true, // Or false when you are ready for live transactions
));
// Do an authorize transaction on the gateway
$transaction = $gateway->authorize(array(
'amount' => '10.00',
'currency' => 'USD',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
));
// Get the response object
$response = $transaction->send();
// Get the value of the payment
$value = $response->getValue();
// Output the value
echo $value;
Output example
10.00
The code above does the following:
- Creates a gateway for the PayPal Express Checkout using the Omnipay::create() method.
- Initializes the gateway with the necessary credentials.
- Does an authorize transaction on the gateway.
- Gets the response object from the transaction.
- Gets the value of the payment from the response object.
- Outputs the value.
Helpful links
- Omnipay website: https://omnipay.thephpleague.com/
- PayPal Express Checkout documentation: https://omnipay.thephpleague.com/gateways/paypal-express/
More of Php Omnipay
- How do I set up and use the Omnipay PHP package?
- How do I use Omnipay with PHP to process zero-dollar transactions?
- How can I use PHP Omnipay to process Yandex payments?
- How can I use Omnipay in PHP?
- How can I use PHP Omnipay to process a billing transaction?
- How do I use the PHP Omnipay Validator?
- How can I use PHP Omnipay to access metadata?
- How do I use PHP Omnipay to verify a payment?
- How do I use Omnipay with PHP?
- How do I update my Omnipay library in PHP?
See more codes...