adnane-ka / omnipay-paddle
Requires
- guzzlehttp/psr7: ^2.4
- nyholm/psr7: ^1.8
- omnipay/common: ^3.3
- php-http/curl-client: ^2.1
- php-http/httplug: ^2.3
- php-http/message: ^1.0
- symfony/http-client: ^6.2
README
Paddle payments gateway for Omnipay payment processing library
Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Tap support for Omnipay.
Installation
composer require adnane-ka/omnipay-paddle
Basic Usage
The following gateways are provided by this package:
- Paddle
This package ineteracts with paddle's API.
For general usage instructions, please see the main Omnipay repository.
Flow
- Configure gateway
- Create a draft transaction
- Display an overlay checkout form for the draft transaction
- Proccess Payment by gateway
- Redirect to proccess payment on website
Example usage
Configuration
use Omnipay\Omnipay; $gateway = Omnipay::create('Paddle'); $gateway->setApiKey('YOUR_API_KEY'); $gateway->setTestMode(true);
Creating a Purchase
$response = $gateway->purchase([ 'amount' => 5.00 * 100, // in cents 'checkoutUrl' => 'http://localhost:8000/checkout.php', // where you'll display the overlay / inline checkout 'returnUrl' => 'http://localhost:8000/complete.php', // where you'll be proccessing the payment 'currency' => 'USD' ])->send(); if ($response->isRedirect()) { // The transaction is created as a draft and you're ready to be redirected to checkout $response->redirect(); } else { // An error occured echo $response->getMessage(); }
Checkout
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Paddle Checkout</title> </head> <body> <script src="https://cdn.paddle.com/paddle/v2/paddle.js"></script> <script type="text/javascript"> Paddle.Environment.set("sandbox"); Paddle.Initialize({ token: "test_4c116d8b4cc5cd9756de9765db9", // Your public API key }); Paddle.Checkout.open({ transactionId: "<?php echo $_GET['transactionId']; ?>", // Locate this from request settings: { successUrl: "<?php echo urldecode($_GET['returnUrl']); ?>" // Locate this from request } }); </script> </body> </html>
Completing Purchase
When users submit the checkout form after they pay using the overlay checkout, they'll be redirected to returnUrl
where you'll be proccessing the payment:
$response = $gateway->completePurchase([ 'transactionId' => $_GET['transactionId'] // sent in request or retrieved from backend ])->send(); if($response->isSuccessful()){ // Payment was successful and charge was captured // $response->getData() echo $response->getTransactionReference(); // payment reference }else{ // Charge was not captured and payment failed echo $response->getMessage(); }
Support
If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.
If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.
If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.