Skip to content

Commit

Permalink
Merge pull request #3 from moddengine/enhancements
Browse files Browse the repository at this point in the history
Enhancements for items & return redirect
  • Loading branch information
alexw23 authored Dec 1, 2019
2 parents f7c3da0 + d6cfe26 commit 88b2340
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,50 @@ The following gateways are provided by this package:

* ZipPay

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository.
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository.\


A quick example looks something like this:

Process your Authorization
```php
$omniZip = Omnipay::create('ZipPay_Rest');
$omniZip->setApiKey($zipApiKey);
$authTx = $omniZip->authorize([
'reference'=> $ref,
'amount' => 10.00,
'currency' => 'AUD',
'returnUrl' => 'https://mysite.com/zip/return',
'card' => $this->OmniPayCardFactory(), //Customers Details, no credit card number
'items' => $this->zipItemList(), // Array of items implementing Omnipay\ZipPay\ItemInterface
]);
$result = $authTx->send();
if($response->isRedirect()) { // Authorize worked
$resData = $result->getData();
$this->saveAuthorizeId($resData['id']);
$response->redirect(); //Sends customer off to ZipPay to complete signup
}
```

Return url (eg /zip/return)
```php
if (!isset($_REQUEST['result']) || $_REQUEST['result'] !== 'approved')
throw new \RuntimeError('Problem with your authorization');
$omniZip = Omnipay::create('ZipPay_Rest');
$omniZip->setApiKey($zipApiKey);
$compTx = $omniZip->completeAuthorize([
'authorityType' => 'checkout_id',
'authorityValue' => $this->getAuthorizeId(),
'amount' => 10.00,
'currency' => 'AUD',
'captureFunds' => true;
]);
$result = $compTx->send();
if($result->isSuccessful())
$this->paid();
else
$this->paymentFailed();
```

## Support

Expand Down
7 changes: 7 additions & 0 deletions src/ItemTypeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Omnipay\ZipPay;

interface ItemTypeInterface extends ItemInterface
{
public function getType();
}
3 changes: 2 additions & 1 deletion src/Message/RestAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Omnipay\ZipPay\Message;

use Omnipay\ZipPay\ItemInterface;
use Omnipay\ZipPay\ItemTypeInterface;
use Omnipay\ZipPay\Message\RestAuthorizeResponse;

/**
Expand Down Expand Up @@ -144,7 +145,7 @@ protected function convertItemToItemData(ItemInterface $item)
'name' => $item->getName(),
'amount' => $item->getQuantity() * $this->formatCurrency($item->getPrice()),
'quantity' => $item->getQuantity(),
'type' => 'sku',
'type' => $item instanceof ItemTypeInterface ? $item->getType() : 'sku',
'reference' => $item->getReference(),
'image_uri' => $item->getImageUri(),
];
Expand Down
16 changes: 15 additions & 1 deletion src/Message/RestAuthorizeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

namespace Omnipay\ZipPay\Message;

use Omnipay\Common\Message\RedirectResponseInterface;
use Omnipay\ZipPay\Message\Response;

/**
* RestAuthorizeResponse
*/
class RestAuthorizeResponse extends Response
class RestAuthorizeResponse extends Response implements
RedirectResponseInterface
{
public function isSuccessful()
{
return false;
}

public function isRedirect()
{
$data = $this->getData();
return isset($data['uri']);
}

public function getRedirectUrl()
{
$data = $this->getData();
return isset($data['uri']) ? $data['uri'] : null;
}
}

0 comments on commit 88b2340

Please sign in to comment.