Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PaidYET as available gateway driver #702

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: [barryvdh]
github: [san0va]
1 change: 1 addition & 0 deletions .phpunit.result.cache

Large diffs are not rendered by default.

62 changes: 2 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,74 +19,15 @@ is fully unit tested, and even comes with an example application to get you star
* Because most payment gateways have exceptionally poor documentation
* Because you are writing a shopping cart and need to support multiple gateways

## TL;DR

Just want to see some code?

```php
use Omnipay\Omnipay;

$gateway = Omnipay::create('Stripe');
$gateway->setApiKey('abc123');

$formData = array('number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2030', 'cvv' => '123');
$response = $gateway->purchase(array('amount' => '10.00', 'currency' => 'USD', 'card' => $formData))->send();

if ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} elseif ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
```

As you can see, Omnipay has a consistent, well thought out API. We try to abstract as much
as possible the differences between the various payments gateways.

## Package Layout

Omnipay is a collection of packages which all depend on the
[omnipay/common](https://github.com/thephpleague/omnipay-common) package to provide
a consistent interface. There are no dependencies on official payment gateway PHP packages -
we prefer to work with the HTTP API directly. Under the hood, we use the popular and powerful
[PHP-HTTP](http://docs.php-http.org/en/latest/index.html) library to make HTTP requests.
A [Guzzle](http://guzzlephp.org/) adapter is required by default, when using `league/omnipay`.

New gateways can be created by cloning the layout of an existing package. When choosing a
name for your package, please don't use the `omnipay` vendor prefix, as this implies that
it is officially supported. You should use your own username as the vendor prefix, and prepend
`omnipay-` to the package name to make it clear that your package works with Omnipay.
For example, if your GitHub username was `santa`, and you were implementing the `giftpay`
payment library, a good name for your composer package would be `santa/omnipay-giftpay`.

## Installation

Omnipay is installed via [Composer](https://getcomposer.org/).
For most uses, you will need to require `league/omnipay` and an individual gateway:

```
composer require league/omnipay:^3 omnipay/paypal
composer require paidyet/omnipay
```

If you want to use your own HTTP Client instead of Guzzle (which is the default for `league/omnipay`),
you can require `omnipay/common` and any `php-http/client-implementation` (see [PHP Http](http://docs.php-http.org/en/latest/clients.html))

```
composer require league/common:^3 omnipay/paypal php-http/buzz-adapter
```

## Upgrade from v2 to v3

If your gateway is supported for v3, you can require that version. Make sure you require `league/omnipay` or a separate Http Adapter.

If there is no version for v3 yet, please raise an issue or upgrade the gateways yourself and create a PR.
See the [Upgrade guide for omnipay/common](https://github.com/thephpleague/omnipay-common/blob/master/UPGRADE.md)

> Note: The package name has been changed from `omnipay/omnipay` to `league/omnipay` for v3

## Payment Gateways

Expand Down Expand Up @@ -210,6 +151,7 @@ Gateway | 2.x | 3.x | Composer Package | Maintainer
[OnePay](https://github.com/dilab/omnipay-onepay) | ✓ | ✓ | dilab/omnipay-onepay | [Xu Ding](https://github.com/dilab)
[Openpay Australia](https://github.com/sudiptpa/openpay) | ✓ | ✓ | sudiptpa/omnipay-openpay | [Sujip Thapa](https://github.com/sudiptpa)
[Oppwa](https://github.com/vdbelt/omnipay-oppwa) | ✓ | ✓ | vdbelt/omnipay-oppwa | [Martin van de Belt](https://github.com/vdbelt)
[PaidYET](https://github.com/PaidYET/paidyet-omnipay) | ✓ | ✓ | paidyet/omnipay | [DeVaughn Skillern](https://github.com/DeVaughnPaidYet)
[PAY. (Pay.nl & Pay.be)](https://github.com/paynl/omnipay-paynl) | ✓ | ✓ | paynl/omnipay-paynl | [Andy Pieters](https://github.com/andypieters)
[PayMongo](https://github.com/oozman/omnipay-paymongo) | - | ✓ | oozman/omnipay-paymongo | [Oozman](https://github.com/oozman)
[Payoo](https://github.com/dilab/omnipay-payoo) | ✓ | ✓ | dilab/omnipay-payoo | [Xu Ding](https://github.com/dilab)
Expand Down
249 changes: 249 additions & 0 deletions RestGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<?php

namespace Omnipay\PaidYET;

use Omnipay\PaidYET\RestGateway;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\GatewayTestCase;

class RestGatewayTest extends GatewayTestCase
{
/** @var RestGateway */
public $gateway;

/** @var array */
public $options;

/** @var array */
public $subscription_options;

public function setUp() : void
{
parent::setUp();

$this->gateway = new RestGateway($this->getHttpClient(), $this->getHttpRequest());
$this->gateway->setToken('TEST-TOKEN-123');
$this->gateway->setTokenExpires(time() + 600);

$this->options = array(
'amount' => '10.00',
'transactionID' => 'abc123',
'credit_card' => new CreditCard(array(
'name' => 'Example User',
'number' => '4111111111111111',
'exp' => '12/24',
'cvv' => '123',
'billing_address' => array(
'address' => '123 test street',
//'line2' => $this->getCard()->getAddress2(),
'city' => 'Los Angeles',
'state' => 'ca',
'postal' => '90001',
//'country_code' => strtoupper($this->getCard()->getCountry()),//
)
)),
);

$this->subscription_options = array(
'transactionID' => 'abc123',
'description' => 'Description goes here',
);
}

public function testBearerToken()
{
$this->gateway->setToken('');
$this->setMockHttpResponse('RestTokenSuccess.txt');

$this->assertFalse($this->gateway->hasToken());
$this->assertEquals('A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0', $this->gateway->getToken()); // triggers request
$this->assertEquals(time() + 28800, $this->gateway->getTokenExpires());
$this->assertTrue($this->gateway->hasToken());
}

public function testBearerTokenReused()
{
$this->setMockHttpResponse('RestTokenSuccess.txt');
$this->gateway->setToken('MYTOKEN');
$this->gateway->setTokenExpires(time() + 60);

$this->assertTrue($this->gateway->hasToken());
$this->assertEquals('MYTOKEN', $this->gateway->getToken());
}

public function testBearerTokenExpires()
{
$this->setMockHttpResponse('RestTokenSuccess.txt');
$this->gateway->setToken('MYTOKEN');
$this->gateway->setTokenExpires(time() - 60);

$this->assertFalse($this->gateway->hasToken());
$this->assertEquals('A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0', $this->gateway->getToken());
}

public function testAuthorize()
{
$this->setMockHttpResponse('RestPurchaseSuccess.txt');

$response = $this->gateway->authorize($this->options)->send();

$this->assertTrue($response->isSuccessful());
// $this->assertEquals('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}

public function testPurchase()
{
//$this->setMockHttpResponse('RestPurchaseSuccess.txt');

$response = $this->gateway->purchase($this->options)->send();

$this->assertTrue($response->isSuccessful());
$this->assertEquals('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}

public function testCapture()
{
$request = $this->gateway->capture(array(
'transactionReference' => 'abc123',
'amount' => 10.00,
'currency' => 'USD',
));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestCaptureRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paidyet.com/v3/transaction/', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}

public function testRefund()
{
$request = $this->gateway->refund(array(
'transactionReference' => 'abc123',
'amount' => 10.00,
'currency' => 'AUD',
));
$request = $this->gateway->refund(array(
'transactionID' => 'abc123'
));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestRefundRequest', $request);
$this->assertSame('abc123', $request->getTransactionID());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paidyet.com/v3/transaction/abc123', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}

public function testFullRefund()
{
$request = $this->gateway->refund(array(
'transactionReference' => 'abc123',
));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestRefundRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paidyet.com/v3/transaction/', $endPoint);
$data = $request->getData();

// we're expecting an empty object here
$json = json_encode($data);
$this->assertEquals('{}', $json);
}

public function testFetchPurchase()
{
$request = $this->gateway->fetchPurchase(array('transactionReference' => 'abc123'));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestFetchPurchaseRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$data = $request->getData();
$this->assertEmpty($data);
}

public function testListPurchase()
{
$request = $this->gateway->listPurchase(array(
'count' => 15,
'startId' => 'PAY123',
'startIndex' => 1,
'startTime' => '2015-09-07T00:00:00Z',
'endTime' => '2015-09-08T00:00:00Z',
));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestListPurchaseRequest', $request);
$this->assertSame(15, $request->getCount());
$this->assertSame('PAY123', $request->getStartId());
$this->assertSame(1, $request->getStartIndex());
$this->assertSame('2015-09-07T00:00:00Z', $request->getStartTime());
$this->assertSame('2015-09-08T00:00:00Z', $request->getEndTime());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paidyet.com/v3/transaction/', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}

public function testCreateCard()
{
$this->setMockHttpResponse('RestCreateCardSuccess.txt');

$response = $this->gateway->createCard($this->options)->send();

$this->assertTrue($response->isSuccessful());
$this->assertEquals('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());
$this->assertNull($response->getMessage());
}


public function testPayWithSavedCard()
{
$this->setMockHttpResponse('RestCreateCardSuccess.txt');
$response = $this->gateway->createCard($this->options)->send();
$cardRef = $response->getCardReference();

$this->setMockHttpResponse('RestPurchaseSuccess.txt');
$response = $this->gateway->purchase(array('amount'=>'10.00', 'cardReference'=>$cardRef))->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}

public function testRefundCapture()
{
$request = $this->gateway->refundCapture(array(
'transactionReference' => 'abc123'
));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestRefundCaptureRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paidyet.com/v3/transaction/', $endPoint);

$request->setAmount('15.99');
$request->setCurrency('USD');
$request->setDescription('Test Description');
$data = $request->getData();
// we're expecting an empty object here
$json = json_encode($data);
$this->assertEquals('{"amount":{"currency":"USD","total":"15.99"},"description":"Test Description"}', $json);
}

public function testVoid()
{
$request = $this->gateway->void(array(
'transactionReference' => 'abc123'
));

$this->assertInstanceOf('\Omnipay\PaidYET\Message\RestVoidRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paidyet.com/v3/transaction/', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}

}
Loading