-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from tomaj/recurrent
Implemented recurrent api
- Loading branch information
Showing
9 changed files
with
404 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
use Guzzle\Http\Exception\ClientErrorResponseException; | ||
use Omnipay\GoPay\GatewayFactory; | ||
use Dotenv\Dotenv; | ||
|
||
$dotenv = Dotenv::create(__DIR__ . '/..'); | ||
$dotenv->load(); | ||
|
||
$goId = $_ENV['GO_ID']; | ||
$clientId = $_ENV['CLIENT_ID']; | ||
$clientSecret = $_ENV['CLIENT_SECRET']; | ||
|
||
$gateway = GatewayFactory::createInstance($goId, $clientId, $clientSecret, true); | ||
|
||
try { | ||
$returnUrl = 'http://localhost:8000/gateway-return.php'; | ||
$notifyUrl = 'http://127.0.0.1/online-payments/uuid/notify'; | ||
$description = 'Shopping at myStore.com'; | ||
|
||
$goPayOrder = [ | ||
'transactionReference' => '3081797108', | ||
]; | ||
|
||
$response = $gateway->cancelRecurrence($goPayOrder); | ||
|
||
echo 'Id: ' . $response->getId() . PHP_EOL; | ||
echo "Result: " . $response->getResult() . PHP_EOL; | ||
echo 'Is Successful: ' . (bool) $response->isSuccessful() . PHP_EOL; | ||
|
||
} catch (ClientErrorResponseException $e) { | ||
dump((string)$e); | ||
dump($e->getResponse()->getBody(true)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
use Guzzle\Http\Exception\ClientErrorResponseException; | ||
use Omnipay\GoPay\GatewayFactory; | ||
use Dotenv\Dotenv; | ||
|
||
$dotenv = Dotenv::create(__DIR__ . '/..'); | ||
$dotenv->load(); | ||
|
||
$goId = $_ENV['GO_ID']; | ||
$clientId = $_ENV['CLIENT_ID']; | ||
$clientSecret = $_ENV['CLIENT_SECRET']; | ||
|
||
$gateway = GatewayFactory::createInstance($goId, $clientId, $clientSecret, true); | ||
|
||
try { | ||
$orderNo = uniqid(); | ||
$returnUrl = 'http://localhost:8000/gateway-return.php'; | ||
$notifyUrl = 'http://127.0.0.1/online-payments/uuid/notify'; | ||
$description = 'Shopping at myStore.com'; | ||
|
||
$goPayOrder = [ | ||
'transactionReference' => '3081796328', | ||
'purchaseData' => [ | ||
'amount' => 1000, | ||
'currency' => 'CZK', | ||
'order_number' => $orderNo, | ||
'order_description' => $description, | ||
'items' => [ | ||
['count' => 1, 'name' => $description, 'amount' => 1000], | ||
], | ||
'eet' => [ | ||
"celk_trzba" => 15000, | ||
"zakl_dan1" => 14000, | ||
"dan1" => 1000, | ||
"zakl_dan2" => 14000, | ||
"dan2" => 1000, | ||
"mena" => 'CZK' | ||
], | ||
], | ||
]; | ||
|
||
$response = $gateway->recurrence($goPayOrder); | ||
|
||
echo 'Our OrderNo: ' . $orderNo . PHP_EOL; | ||
echo "Parent id: " . $response->getParentId() . PHP_EOL; | ||
echo "TransactionReference: " . $response->getTransactionReference() . PHP_EOL; | ||
echo 'Is Successful: ' . (bool) $response->isSuccessful() . PHP_EOL; | ||
echo 'Is redirect: ' . (bool) $response->isRedirect() . PHP_EOL; | ||
|
||
} catch (ClientErrorResponseException $e) { | ||
dump((string)$e); | ||
dump($e->getResponse()->getBody(true)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Omnipay\GoPay\Message; | ||
|
||
use Omnipay\Common\Message\AbstractRequest; | ||
|
||
class CancelRecurrenceRequest extends AbstractRequest | ||
{ | ||
|
||
/** | ||
* Get the raw data array for this message. The format of this varies from gateway to | ||
* gateway, but will usually be either an associative array, or a SimpleXMLElement. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->getParameter('transactionReference'); | ||
} | ||
|
||
/** | ||
* Get the transaction reference which was used to create recurrent profile | ||
* | ||
* @return mixed | ||
*/ | ||
public function getTransactionReference() | ||
{ | ||
return $this->getParameter('transactionReference'); | ||
} | ||
|
||
/** | ||
* Send the request with specified data | ||
* | ||
* @param mixed $data The data to send | ||
* @return RecurrenceResponse | ||
*/ | ||
public function sendData($data) | ||
{ | ||
$headers = [ | ||
'Accept' => 'application/json', | ||
'Accept-Language' => 'en-US', | ||
'Content-Type' => 'application/x-www-form-urlencoded', | ||
'Authorization' => $this->getParameter('token'), | ||
]; | ||
|
||
$transactionReference = $this->getTransactionReference(); | ||
|
||
$httpResponse = $this->httpClient->request( | ||
'POST', | ||
$this->getParameter('apiUrl') . '/api/payments/payment/' . $transactionReference . '/void-recurrence', | ||
$headers, | ||
json_encode($data) | ||
); | ||
|
||
$purchaseResponseData = json_decode($httpResponse->getBody()->getContents(), true); | ||
|
||
$response = new CancelRecurrenceResponse($this, $purchaseResponseData); | ||
return $response; | ||
} | ||
|
||
/** | ||
* @param string $token | ||
*/ | ||
public function setToken($token) | ||
{ | ||
$this->setParameter('token', $token); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function setPurchaseData($data) | ||
{ | ||
$this->setParameter('purchaseData', $data); | ||
} | ||
|
||
/** | ||
* @param string $apiUrl | ||
*/ | ||
public function setApiUrl($apiUrl) | ||
{ | ||
$this->setParameter('apiUrl', $apiUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Omnipay\GoPay\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RedirectResponseInterface; | ||
|
||
class CancelRecurrenceResponse extends AbstractResponse implements RedirectResponseInterface | ||
{ | ||
/** | ||
* Is the response successful? | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
return $this->getResult() == 'FINISHED'; | ||
} | ||
|
||
public function isRedirect() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Gets the redirect form data array, if the redirect method is POST. | ||
*/ | ||
public function getRedirectData() | ||
{ | ||
return null; | ||
} | ||
|
||
public function getId() | ||
{ | ||
if (isset($this->data['id']) && !empty(isset($this->data['id']))) { | ||
return (string) $this->data['id']; | ||
} | ||
return null; | ||
} | ||
|
||
public function getResult() | ||
{ | ||
if (isset($this->data['result']) && !empty($this->data['result'])) { | ||
return (string) $this->data['result']; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Omnipay\GoPay\Message; | ||
|
||
use Omnipay\Common\Message\AbstractRequest; | ||
|
||
class RecurrenceRequest extends AbstractRequest | ||
{ | ||
|
||
/** | ||
* Get the raw data array for this message. The format of this varies from gateway to | ||
* gateway, but will usually be either an associative array, or a SimpleXMLElement. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->getParameter('purchaseData'); | ||
} | ||
|
||
/** | ||
* Get the transaction reference which was used to create recurrent profile | ||
* | ||
* @return mixed | ||
*/ | ||
public function getTransactionReference() | ||
{ | ||
return $this->getParameter('transactionReference'); | ||
} | ||
|
||
/** | ||
* Send the request with specified data | ||
* | ||
* @param mixed $data The data to send | ||
* @return RecurrenceResponse | ||
*/ | ||
public function sendData($data) | ||
{ | ||
$headers = [ | ||
'Accept' => 'application/json', | ||
'Accept-Language' => 'en-US', | ||
'Content-Type' => 'application/json', | ||
'Authorization' => $this->getParameter('token'), | ||
]; | ||
|
||
$transactionReference = $this->getTransactionReference(); | ||
|
||
$httpResponse = $this->httpClient->request( | ||
'POST', | ||
$this->getParameter('apiUrl') . '/api/payments/payment/' . $transactionReference . '/create-recurrence', | ||
$headers, | ||
json_encode($data) | ||
); | ||
|
||
$purchaseResponseData = json_decode($httpResponse->getBody()->getContents(), true); | ||
|
||
$response = new RecurrenceResponse($this, $purchaseResponseData); | ||
return $response; | ||
} | ||
|
||
/** | ||
* @param string $token | ||
*/ | ||
public function setToken($token) | ||
{ | ||
$this->setParameter('token', $token); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function setPurchaseData($data) | ||
{ | ||
$this->setParameter('purchaseData', $data); | ||
} | ||
|
||
/** | ||
* @param string $apiUrl | ||
*/ | ||
public function setApiUrl($apiUrl) | ||
{ | ||
$this->setParameter('apiUrl', $apiUrl); | ||
} | ||
} |
Oops, something went wrong.