From 22f2ca453c9ca4fd7d754aa0b76c7b5486f2a67b Mon Sep 17 00:00:00 2001 From: Lee Siong Chan Date: Fri, 1 Apr 2016 10:48:11 +0800 Subject: [PATCH] Update README --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++-- tests/GatewayTest.php | 2 -- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad25d7a..cfb0047 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,63 @@ The following gateways are provided by this package: For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. -## Usage +## Example + +### Create a purchase request + +The example below explains how you can create a purchase request then send it. + +```php +$gateway = Omnipay::create('MOLPay'); + +$gateway->setCurrency('MYR'); +$gateway->setEnableIPN(true); // Optional +$gateway->setLocale('en'); // Optional +$gateway->setMerchantId('test1234'); +$gateway->setVerifyKey('abcdefg'); + +$options = [ + 'amount' => '10.00', + 'card' => new CreditCard(array( + 'country' => 'MY', + 'email' => 'ahlee2326@me.com', + 'name' => 'Lee Siong Chan', + 'phone' => '0123456789', + )), + 'description' => 'Test Payment', + 'transactionId' => '20160331082207680000', + 'paymentMethod' => 'credit', // Optional +]; + +$response = $gateway->purchase($options)->send(); + +// Get the MOLPay payment URL (https://www.onlinepayment.com.my/MOLPay/pay/...) +$redirectUrl = $response->getRedirectUrl(); +``` + +### Complete a purchase request + +When the user submit the payment form, the gateway will redirect you to the return URL that you have specified in MOLPay. The code below gives an example how to handle the server feedback answer. + +```php +$response = $gateway->completePurchase($options)->send(); -Coming soon... +if ($response->isSuccessful()) { + // Do something + echo $response->getTransactionReference(); +} elseif ($response->isPending()) { + // Do something +} elseif ($response->isCancelled()) { + // Do something +} else { + // Error +} + +// Check if is a callback notification +if ($response->isCallbackNotification()) { + // Do something +} +``` ## Out Of Scope diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 5fa561a..93c911f 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -34,8 +34,6 @@ public function setUp() 'description' => 'Test Payment', 'transactionId' => '20160331082207680000', 'paymentMethod' => 'credit', - 'returnUrl' => 'https://example.com/return', - 'notifyUrl' => 'https://example.com/notify', ); }