From e1a306e87185016900324e16af78386482e9ae6e Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 13 Jun 2024 15:13:39 -0700 Subject: [PATCH 01/14] initial release --- README.md | 1 + composer.json | 17 +- src/Message/AbstractRestRequest.php | 219 ++++++++++ src/Message/AbstractRestVoidRequest.php | 218 ++++++++++ src/Message/RestAuthorizeRequest.php | 138 ++++++ src/Message/RestAuthorizeResponse.php | 98 +++++ src/Message/RestCaptureRequest.php | 33 ++ src/Message/RestCompletePurchaseRequest.php | 34 ++ src/Message/RestCreateCardRequest.php | 47 +++ src/Message/RestFetchPurchaseRequest.php | 41 ++ src/Message/RestFetchTransactionRequest.php | 37 ++ src/Message/RestListPurchaseRequest.php | 159 +++++++ src/Message/RestPurchaseRequest.php | 21 + src/Message/RestRefundCaptureRequest.php | 35 ++ src/Message/RestRefundRequest.php | 42 ++ src/Message/RestResponse.php | 72 ++++ src/Message/RestTokenRequest.php | 42 ++ src/Message/RestVoidRequest.php | 37 ++ src/RestGateway.php | 441 ++++++++++++++++++++ 19 files changed, 1725 insertions(+), 7 deletions(-) create mode 100644 src/Message/AbstractRestRequest.php create mode 100644 src/Message/AbstractRestVoidRequest.php create mode 100644 src/Message/RestAuthorizeRequest.php create mode 100644 src/Message/RestAuthorizeResponse.php create mode 100644 src/Message/RestCaptureRequest.php create mode 100644 src/Message/RestCompletePurchaseRequest.php create mode 100644 src/Message/RestCreateCardRequest.php create mode 100644 src/Message/RestFetchPurchaseRequest.php create mode 100644 src/Message/RestFetchTransactionRequest.php create mode 100644 src/Message/RestListPurchaseRequest.php create mode 100644 src/Message/RestPurchaseRequest.php create mode 100644 src/Message/RestRefundCaptureRequest.php create mode 100644 src/Message/RestRefundRequest.php create mode 100644 src/Message/RestResponse.php create mode 100644 src/Message/RestTokenRequest.php create mode 100644 src/Message/RestVoidRequest.php create mode 100644 src/RestGateway.php diff --git a/README.md b/README.md index 3b1f96a5..6e8b99b3 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,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) diff --git a/composer.json b/composer.json index 9bbc6db9..ad3e999a 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,17 @@ { - "name": "league/omnipay", - "type": "metapackage", - "description": "Omnipay payment processing library", + "name": "paidyet/omnipay", + "type": "library", + "description": "PaidYET driver for the Omnipay payment processing library", "keywords": [ - "omnipay", - "checkout", - "creditcard", + "paidyet", + "paid yet", + "gateway", + "merchant", + "secure", + "pay", "payment" ], - "homepage": "https://omnipay.thephpleague.com/", + "homepage": "https://github.com/PaidYET", "license": "MIT", "authors": [ { diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php new file mode 100644 index 00000000..300ef88b --- /dev/null +++ b/src/Message/AbstractRestRequest.php @@ -0,0 +1,219 @@ +referrerCode; + } + + /** + * @param string $referrerCode + */ + public function setReferrerCode($referrerCode) + { + $this->referrerCode = $referrerCode; + } + + public function getClientId() + { + return $this->getParameter('clientId'); + } + + public function setClientId($value) + { + return $this->setParameter('clientId', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getToken() + { + $data = ['key'=>$this->getSecret()]; + $body = $this->toJSON($data); + $httpResponse = $this->httpClient->request( + $this->getHttpMethod(), + $this->getLoginEndpoint(), + array( + 'Accept' => 'application/json', + 'Content-type' => 'application/json', + ), + $body + ); + //print_r($this->getLoginEndpoint()); + //print_r($body); + $contents = $httpResponse->getBody()->getContents(); + $contentsObj = JSON_decode($contents); + //print_r($contentsObj); + //print_r($contentsObj->result); + //exit(); + return $contentsObj->result->token; + + } + + public function setToken($value) + { + return $this->setParameter('token', $value); + } + + public function getPayerId() + { + return $this->getParameter('payerId'); + } + + public function setPayerId($value) + { + return $this->setParameter('payerId', $value); + } + + /** + * Get HTTP Method. + * + * This is nearly always POST but can be over-ridden in sub classes. + * + * @return string + */ + protected function getHttpMethod() + { + return 'POST'; + } + + protected function getEndpoint() + { + $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; + return $base . '/' . self::API_VERSION; + } + + protected function getLoginEndpoint() + { + $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; + $base .= '/' . self::API_VERSION; + + return $base . '/login'; + } + + public function sendData($data) + { + + // Guzzle HTTP Client createRequest does funny things when a GET request + // has attached data, so don't send the data if the method is GET. + if ($this->getHttpMethod() == 'GET') { + $requestUrl = $this->getEndpoint() . '?' . http_build_query($data); + $body = null; + } else { + $body = $this->toJSON($data); + $requestUrl = $this->getEndpoint(); + } + //print_r($this->getEndpoint()); + //exit(); + + // Print token: + //print_r($this->getToken()); + //exit(); + try { + $httpResponse = $this->httpClient->request( + $this->getHttpMethod(), + $this->getEndpoint(), + array( + 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . $this->getToken(), + 'Content-type' => 'application/json', + ), + $body + ); + // Empty response body should be parsed also as and empty array + $body = (string) $httpResponse->getBody()->getContents(); + $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array(); + //print_r($jsonToArrayResponse); + //exit(); + return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); + } catch (\Exception $e) { + throw new InvalidResponseException( + 'Error communicating with payment gateway: ' . $e->getMessage(), + $e->getCode() + ); + } + } + + + public function toJSON($data, $options = 0) + { + // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option + // Instead we would use the str_replace command for now. + // TODO: Replace this code with return json_encode($this->toArray(), $options | 64); once we support PHP >= 5.4 + if (version_compare(phpversion(), '5.4.0', '>=') === true) { + return json_encode($data, $options | 64); + } + return str_replace('\\/', '/', json_encode($data, $options)); + } + + protected function createResponse($data, $statusCode) + { + return $this->response = new RestResponse($this, $data, $statusCode); + } +} diff --git a/src/Message/AbstractRestVoidRequest.php b/src/Message/AbstractRestVoidRequest.php new file mode 100644 index 00000000..1c839a61 --- /dev/null +++ b/src/Message/AbstractRestVoidRequest.php @@ -0,0 +1,218 @@ +referrerCode; + } + + /** + * @param string $referrerCode + */ + public function setReferrerCode($referrerCode) + { + $this->referrerCode = $referrerCode; + } + + public function getClientId() + { + return $this->getParameter('clientId'); + } + + public function setClientId($value) + { + return $this->setParameter('clientId', $value); + } + + public function getSecret() + { + return $this->getParameter('secret'); + } + + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + public function getToken() + { + $data = ['key'=>$this->getSecret()]; + $body = $this->toJSON($data); + $httpResponse = $this->httpClient->request( + $this->getHttpMethod(), + $this->getLoginEndpoint(), + array( + 'Accept' => 'application/json', + 'Content-type' => 'application/json', + ), + $body + ); + //print_r($this->getLoginEndpoint()); + //print_r($body); + $contents = $httpResponse->getBody()->getContents(); + $contentsObj = JSON_decode($contents); + //print_r($contentsObj); + //print_r($contentsObj->result); + //exit(); + return $contentsObj->result->token; + + } + + public function setToken($value) + { + return $this->setParameter('token', $value); + } + + public function getPayerId() + { + return $this->getParameter('payerId'); + } + + public function setPayerId($value) + { + return $this->setParameter('payerId', $value); + } + + /** + * Get HTTP Method. + * + * This is nearly always POST but can be over-ridden in sub classes. + * + * @return string + */ + protected function getHttpMethod() + { + return 'POST'; + } + + protected function getEndpoint() + { + $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; + return $base . '/' . self::API_VERSION; + } + + protected function getLoginEndpoint() + { + $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; + $base .= '/' . self::API_VERSION; + + return $base . '/login'; + } + + public function sendData($data) + { + + // Guzzle HTTP Client createRequest does funny things when a GET request + // has attached data, so don't send the data if the method is GET. + if ($this->getHttpMethod() == 'GET') { + $requestUrl = $this->getEndpoint() . '?' . http_build_query($data); + $body = null; + } else { + $body = $this->toJSON($data); + $requestUrl = $this->getEndpoint(); + } + //print_r($this->getEndpoint()); + //exit(); + print_r($body); + // Print token: + //print_r($this->getToken()); + //exit(); + try { + $httpResponse = $this->httpClient->request( + $this->getHttpMethod(), + $this->getEndpoint(), + array( + 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . $this->getToken(), + 'Content-type' => 'application/json', + ), + $body + ); + // Empty response body should be parsed also as and empty array + $body = (string) $httpResponse->getBody()->getContents(); + $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array(); + //print_r($jsonToArrayResponse); + //exit(); + return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); + } catch (\Exception $e) { + throw new InvalidResponseException( + 'Error communicating with payment gateway: ' . $e->getMessage(), + $e->getCode() + ); + } + } + + public function toJSON($data, $options = 0) + { + // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option + // Instead we would use the str_replace command for now. + // TODO: Replace this code with return json_encode($this->toArray(), $options | 64); once we support PHP >= 5.4 + if (version_compare(phpversion(), '5.4.0', '>=') === true) { + return json_encode($data, $options | 64); + } + return str_replace('\\/', '/', json_encode($data, $options)); + } + + protected function createResponse($data, $statusCode) + { + return $this->response = new RestResponse($this, $data, $statusCode); + } +} diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php new file mode 100644 index 00000000..5fb7bee7 --- /dev/null +++ b/src/Message/RestAuthorizeRequest.php @@ -0,0 +1,138 @@ + 'auth', + 'amount' => $this->getAmount(), + + + /* 'experience_profile_id' => $this->getExperienceProfileId() */ + ); + + + + + if ($this->getCardReference()) { + $this->validate('amount'); + + $data['payer']['funding_instruments'][] = array( + 'credit_card_token' => array( + 'credit_card_id' => $this->getCardReference(), + ), + ); + } elseif ($this->getCard()) { + $this->validate('amount', 'card'); + $this->getCard()->validate(); + + $data['credit_card'] = array( + + 'number' => $this->getCard()->getNumber(), + //'type' => $this->getCard()->getBrand(), + 'exp' => $this->getCard()->getExpiryMonth()."/".$this->getCard()->getExpiryYear(), + //'expire_year' => $this->getCard()->getExpiryYear(), + 'cvv' => $this->getCard()->getCvv(), + 'name' => $this->getCard()->getFirstName()." ".$this->getCard()->getLastName(), + //'type' => $this->getCard()->getLastName(), + 'billing_address' => array( + 'address' => $this->getCard()->getAddress1(), + //'line2' => $this->getCard()->getAddress2(), + 'city' => $this->getCard()->getCity(), + 'state' => $this->getCard()->getState(), + 'postal' => $this->getCard()->getPostcode(), + //'country_code' => strtoupper($this->getCard()->getCountry()),// + ) + + ); + + + $line2 = $this->getCard()->getAddress2(); + + } else { + $this->validate('amount', 'returnUrl', 'cancelUrl'); + + unset($data['credit_card']); + + } + + return $data; + } + + /** + * Get the experience profile id + * + * @return string + * + *public function getExperienceProfileId() + *{ + * return $this->getParameter('experienceProfileId'); + *} + */ + + /** + * Set the experience profile id + * + * @param string $value + * @return RestAuthorizeRequest provides a fluent interface. + * + * public function setExperienceProfileId($value) + *{ + * return $this->setParameter('experienceProfileId', $value); + * } + */ + + /** + * Get transaction description. + * + * The REST API does not currently have support for passing an invoice number + * or transaction ID. + * + * @return string + */ + public function getDescription() + { + $id = $this->getTransactionId(); + $desc = parent::getDescription(); + + if (empty($id)) { + return $desc; + } elseif (empty($desc)) { + return $id; + } else { + return "$id : $desc"; + } + } + + /** + * Get transaction endpoint. + * + * Authorization of payments is done using the /transaction resource. + * + * @return string + */ + protected function getEndpoint() + { + return parent::getEndpoint() . '/transaction'; + } + + protected function createResponse($data, $statusCode) + { + return $this->response = new RestAuthorizeResponse($this, $data, $statusCode); + } +} diff --git a/src/Message/RestAuthorizeResponse.php b/src/Message/RestAuthorizeResponse.php new file mode 100644 index 00000000..d726be6d --- /dev/null +++ b/src/Message/RestAuthorizeResponse.php @@ -0,0 +1,98 @@ +data['error']) && $this->getCode() == 201; + } + + public function isRedirect() + { + return $this->getRedirectUrl() !== null; + } + + public function getRedirectUrl() + { + if (isset($this->data['links']) && is_array($this->data['links'])) { + foreach ($this->data['links'] as $key => $value) { + if ($value['rel'] == 'approval_url') { + return $value['href']; + } + } + } + + return null; + } + + /** + * Get the URL to complete (execute) the purchase or agreement. + * + * The URL is embedded in the links section of the purchase or create + * subscription request response. + * + * @return string + */ + public function getCompleteUrl() + { + if (isset($this->data['links']) && is_array($this->data['links'])) { + foreach ($this->data['links'] as $key => $value) { + if ($value['rel'] == 'execute') { + return $value['href']; + } + } + } + + return null; + } + + public function getTransactionReference() + { + + $completeUrl = $this->getCompleteUrl(); + if (empty($completeUrl)) { + return parent::getTransactionReference(); + } + + $urlParts = explode('/', $completeUrl); + + // The last element of the URL should be "execute" + $execute = end($urlParts); + if (!in_array($execute, array('execute', 'agreement-execute'))) { + return parent::getTransactionReference(); + } + + // The penultimate element should be the transaction reference + return prev($urlParts); + } + + /** + * Get the required redirect method (either GET or POST). + * + * @return string + */ + public function getRedirectMethod() + { + return 'GET'; + } + + /** + * Gets the redirect form data array, if the redirect method is POST. + * + * @return null + */ + public function getRedirectData() + { + return null; + } +} diff --git a/src/Message/RestCaptureRequest.php b/src/Message/RestCaptureRequest.php new file mode 100644 index 00000000..7c62add3 --- /dev/null +++ b/src/Message/RestCaptureRequest.php @@ -0,0 +1,33 @@ +getAmount(); + return $data; + } + + function getHttpMethod() + { + return 'PUT'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/transaction' . '/' . $this->getTransactionId(); + } +} diff --git a/src/Message/RestCompletePurchaseRequest.php b/src/Message/RestCompletePurchaseRequest.php new file mode 100644 index 00000000..a106c5a0 --- /dev/null +++ b/src/Message/RestCompletePurchaseRequest.php @@ -0,0 +1,34 @@ +validate('transactionReference', 'payerId'); + + $data = array( + 'payer_id' => $this->getPayerId() + ); + + return $data; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/payment/' . $this->getTransactionReference() . '/execute'; + } +} diff --git a/src/Message/RestCreateCardRequest.php b/src/Message/RestCreateCardRequest.php new file mode 100644 index 00000000..e355f45f --- /dev/null +++ b/src/Message/RestCreateCardRequest.php @@ -0,0 +1,47 @@ +validate('card'); + $this->getCard()->validate(); + + $data = array( + 'number' => $this->getCard()->getNumber(), + 'exp' => $this->getCard()->getExpiryMonth()."/".$this->getCard()->getExpiryYear(), + 'cvv' => $this->getCard()->getCvv(), + 'name' => $this->getCard()->getFirstName()."/".$this->getCard()->getLastName(), + 'billing_address' => array( + 'line1' => $this->getCard()->getAddress1(), + //'line2' => $this->getCard()->getAddress2(), + 'city' => $this->getCard()->getCity(), + 'state' => $this->getCard()->getState(), + 'postal_code' => $this->getCard()->getPostcode(), + ) + ); + + // There's currently a quirk with the REST API that requires line2 to be + // non-empty if it's present. Jul 14, 2014 + $line2 = $this->getCard()->getAddress2(); + if (!empty($line2)) { + $data['billing_address']['line2'] = $line2; + } + + return $data; + } + + protected function getEndpoint() + { + return parent::getEndpoint() . '/card'; + } +} diff --git a/src/Message/RestFetchPurchaseRequest.php b/src/Message/RestFetchPurchaseRequest.php new file mode 100644 index 00000000..2f588923 --- /dev/null +++ b/src/Message/RestFetchPurchaseRequest.php @@ -0,0 +1,41 @@ +validate('transactionReference'); + return array(); + } + + /** + * Get HTTP Method. + * + * The HTTP method for fetchTransaction requests must be GET. + * Using POST results in an error 500. + * + * @return string + */ + protected function getHttpMethod() + { + return 'GET'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/payment/' . $this->getTransactionReference(); + } +} diff --git a/src/Message/RestFetchTransactionRequest.php b/src/Message/RestFetchTransactionRequest.php new file mode 100644 index 00000000..7c6b831d --- /dev/null +++ b/src/Message/RestFetchTransactionRequest.php @@ -0,0 +1,37 @@ +validate('transactionReference'); + return array(); + } + + /** + * Get HTTP Method. + * + * The HTTP method for fetchTransaction requests must be GET. + * Using POST results in an error 500. + * + * @return string + */ + protected function getHttpMethod() + { + return 'GET'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/sale/' . $this->getTransactionReference(); + } +} diff --git a/src/Message/RestListPurchaseRequest.php b/src/Message/RestListPurchaseRequest.php new file mode 100644 index 00000000..b5625b47 --- /dev/null +++ b/src/Message/RestListPurchaseRequest.php @@ -0,0 +1,159 @@ +getParameter('count'); + } + + /** + * Set the request count + * + * @param integer $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setCount($value) + { + return $this->setParameter('count', $value); + } + + /** + * Get the request startId + * + * @return string + */ + public function getStartId() + { + return $this->getParameter('startId'); + } + + /** + * Set the request startId + * + * @param string $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setStartId($value) + { + return $this->setParameter('startId', $value); + } + + /** + * Get the request startIndex + * + * @return integer + */ + public function getStartIndex() + { + return $this->getParameter('startIndex'); + } + + /** + * Set the request startIndex + * + * @param integer $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setStartIndex($value) + { + return $this->setParameter('startIndex', $value); + } + + /** + * Get the request startTime + * + * @return string + */ + public function getStartTime() + { + return $this->getParameter('startTime'); + } + + /** + * Set the request startTime + * + * @param string|\DateTime $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setStartTime($value) + { + if ($value instanceof \DateTime) { + $value->setTimezone(new \DateTimeZone('UTC')); + $value = $value->format('Y-m-d\TH:i:s\Z'); + } + return $this->setParameter('startTime', $value); + } + + /** + * Get the request endTime + * + * @return string + */ + public function getEndTime() + { + return $this->getParameter('endTime'); + } + + /** + * Set the request endTime + * + * @param string|\DateTime $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setEndTime($value) + { + if ($value instanceof \DateTime) { + $value->setTimezone(new \DateTimeZone('UTC')); + $value = $value->format('Y-m-d\TH:i:s\Z'); + } + return $this->setParameter('endTime', $value); + } + + public function getData() + { + return array( + 'count' => $this->getCount(), + 'start_id' => $this->getStartId(), + 'start_index' => $this->getStartIndex(), + 'start_time' => $this->getStartTime(), + 'end_time' => $this->getEndTime(), + ); + } + + /** + * Get HTTP Method. + * + * The HTTP method for listPurchase requests must be GET. + * + * @return string + */ + protected function getHttpMethod() + { + return 'GET'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/payment'; + } +} diff --git a/src/Message/RestPurchaseRequest.php b/src/Message/RestPurchaseRequest.php new file mode 100644 index 00000000..35e192ae --- /dev/null +++ b/src/Message/RestPurchaseRequest.php @@ -0,0 +1,21 @@ +validate('transactionReference'); + + return array( + 'amount' => array( + 'currency' => $this->getCurrency(), + 'total' => $this->getAmount(), + ), + 'description' => $this->getDescription(), + ); + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/capture/' . $this->getTransactionReference() . '/refund'; + } +} diff --git a/src/Message/RestRefundRequest.php b/src/Message/RestRefundRequest.php new file mode 100644 index 00000000..b0c9039e --- /dev/null +++ b/src/Message/RestRefundRequest.php @@ -0,0 +1,42 @@ +validate('transactionId'); + $data = array( + 'type' => 'refund', + ); + return $data; + + if ($this->getAmount() > 0) { + return array( + 'amount' => array( + 'currency' => $this->getCurrency(), + 'total' => $this->getAmount(), + ), + 'description' => $this->getDescription(), + ); + } else { + return new \stdClass(); + } + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/transaction' . '/' . $this->getTransactionId(); + + } + +} diff --git a/src/Message/RestResponse.php b/src/Message/RestResponse.php new file mode 100644 index 00000000..5605cfc8 --- /dev/null +++ b/src/Message/RestResponse.php @@ -0,0 +1,72 @@ +statusCode = $statusCode; + } + + public function isSuccessful() + { + return empty($this->data['error']) && $this->getCode() < 400; + } + + public function getTransactionReference() + { + // This is usually correct for payments, authorizations, etc + if (!empty($this->data['transactions']) && !empty($this->data['transactions'][0]['related_resources'])) { + foreach (array('sale', 'authorization') as $type) { + if (!empty($this->data['transactions'][0]['related_resources'][0][$type])) { + return $this->data['transactions'][0]['related_resources'][0][$type]['id']; + } + } + } + + // This is a fallback, but is correct for fetch transaction and possibly others + if (!empty($this->data['id'])) { + return $this->data['id']; + } + + return null; + } + + public function getMessage() + { + if (isset($this->data['error_description'])) { + return $this->data['error_description']; + } + + if (isset($this->data['message'])) { + return $this->data['message']; + } + + return null; + } + + public function getCode() + { + return $this->statusCode; + } + + public function getCardReference() + { + if (isset($this->data['id'])) { + return $this->data['id']; + } + } +} diff --git a/src/Message/RestTokenRequest.php b/src/Message/RestTokenRequest.php new file mode 100644 index 00000000..ea64008d --- /dev/null +++ b/src/Message/RestTokenRequest.php @@ -0,0 +1,42 @@ + 'client_credentials'); + } + + protected function getEndpoint() + { + return parent::getEndpoint() . '/oauth2/token'; + } + + public function sendData($data) + { + $body = $data ? http_build_query($data, '', '&') : null; + $httpResponse = $this->httpClient->request( + $this->getHttpMethod(), + $this->getEndpoint(), + array( + 'Accept' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode("{$this->getClientId()}:{$this->getSecret()}"), + ), + $body + ); + // Empty response body should be parsed also as and empty array + $body = (string) $httpResponse->getBody()->getContents(); + $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array(); + return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode()); + } +} diff --git a/src/Message/RestVoidRequest.php b/src/Message/RestVoidRequest.php new file mode 100644 index 00000000..f55412f8 --- /dev/null +++ b/src/Message/RestVoidRequest.php @@ -0,0 +1,37 @@ + 'void', + ); + return $data; + } + + function getHttpMethod() + { + return 'PATCH'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/transaction' . '/' . $this->getTransactionId(); + } +} diff --git a/src/RestGateway.php b/src/RestGateway.php new file mode 100644 index 00000000..545362ab --- /dev/null +++ b/src/RestGateway.php @@ -0,0 +1,441 @@ + + * // Create a gateway for the PaidYET RestGateway + * // (routes to GatewayFactory::create) + * $gateway = Omnipay::create('PaidYET_Rest'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'clientId' => 'merchant_id', + * 'secret' => 'secret', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * + * #### Direct Credit Card Payment + * + * + * PaidYET Class using REST API + * + * This class forms the gateway class for PaidYET requests via the PaidYET APIs. + * + * The PaidYET API uses a RESTful endpoint structure. Bearer token authentication is used. + * Request and response payloads are formatted as JSON. + * + * The PaidYET APIs are supported in two environments. Use the Sandbox environment + * for testing purposes, then move to the live environment for production processing. + * When testing, generate an access token with your test credentials to make calls to + * the Sandbox URIs. When you’re set to go live, use the live credentials assigned to + * your app to generate a new access token to be used with the live URIs. + * + * + * ### Credentials + * + * Authenticate with your PaidYET secret and Merchant ID to retrieve a bearer token. + * The bearer token will expire periodically and you will need to obtain a new one. + * + * merchant_id + * Merchant's PaidYET UUID. This field is only required when using a Partner level API secret. + * This is found in the Merchant list in the Partner Portal. + * + * secret + * Merchant's PaidYET api secret. These can be managed in the PaidYET dashboard + * + * + * @link https://paidyet.readme.io/ + * @see Omnipay\PaidYET\Message\AbstractRestRequest + * @see Omnipay\PaidYET\Message\AbstractRestRequest + */ +class RestGateway extends AbstractGateway +{ + + // Constants used in plan creation + const BILLING_PLAN_TYPE_FIXED = 'FIXED'; + const BILLING_PLAN_TYPE_INFINITE = 'INFINITE'; + const BILLING_PLAN_FREQUENCY_DAY = 'DAY'; + const BILLING_PLAN_FREQUENCY_WEEK = 'WEEK'; + const BILLING_PLAN_FREQUENCY_MONTH = 'MONTH'; + const BILLING_PLAN_FREQUENCY_YEAR = 'YEAR'; + const BILLING_PLAN_STATE_CREATED = 'CREATED'; + const BILLING_PLAN_STATE_ACTIVE = 'ACTIVE'; + const BILLING_PLAN_STATE_INACTIVE = 'INACTIVE'; + const BILLING_PLAN_STATE_DELETED = 'DELETED'; + const PAYMENT_TRIAL = 'TRIAL'; + const PAYMENT_REGULAR = 'REGULAR'; + + public function getName() + { + return 'PaidYET REST'; + } + + public function getDefaultParameters() + { + return array( + 'clientId' => '', + 'secret' => '', + 'token' => '', + 'testMode' => false, + ); + } + + + /** + * Token Access + * + * Get an access token by using the your clientId:secret as your Basic Auth + * credentials. + * + * @return string + */ + public function getClientId() + { + return $this->getParameter('clientId'); + } + + /** + * Set OAuth 2.0 client ID for the access token. + * + * Get an access token by using the OAuth 2.0 client_credentials + * token grant type with your clientId:secret as your Basic Auth + * credentials. + * + * @param string $value + * @return RestGateway provides a fluent interface + */ + public function setClientId($value) + { + return $this->setParameter('clientId', $value); + } + + /** + * Get OAuth 2.0 secret for the access token. + * + * Get an access token by using the OAuth 2.0 client_credentials + * token grant type with your clientId:secret as your Basic Auth + * credentials. + * + * @return string + */ + public function getSecret() + { + return $this->getParameter('secret'); + } + + /** + * Set secret (apisecret) for the access token. + * + * + * @param string $value + * @return RestGateway provides a fluent interface + */ + public function setSecret($value) + { + return $this->setParameter('secret', $value); + } + + /** + * Get access token. + * + * @param bool $createIfNeeded [optional] - If there is not an active token present, should we create one? + * @return string + */ + public function getToken($createIfNeeded = true) + { + if ($createIfNeeded && !$this->hasToken()) { + $response = $this->createToken()->send(); + if ($response->isSuccessful()) { + $data = $response->getData(); + if (isset($data['access_token'])) { + $this->setToken($data['access_token']); + $this->setTokenExpires(time() + $data['expires_in']); + } + } + } + + return $this->getParameter('token'); + } + + /** + * Create access token request. + * + * @return \Omnipay\PaidYET\Message\RestTokenRequest + */ + public function createToken() + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestTokenRequest', array()); + } + + /** + * Set access token. + * + * @param string $value + * @return RestGateway provides a fluent interface + */ + public function setToken($value) + { + return $this->setParameter('token', $value); + } + + /** + * Get access token expiry time. + * + * @return integer + */ + public function getTokenExpires() + { + return $this->getParameter('tokenExpires'); + } + + /** + * Set access token expiry time. + * + * @param integer $value + * @return RestGateway provides a fluent interface + */ + public function setTokenExpires($value) + { + return $this->setParameter('tokenExpires', $value); + } + + /** + * Is there a bearer token and is it still valid? + * + * @return bool + */ + public function hasToken() + { + $token = $this->getParameter('token'); + + $expires = $this->getTokenExpires(); + if (!empty($expires) && !is_numeric($expires)) { + $expires = strtotime($expires); + } + + return !empty($token) && time() < $expires; + } + + /** + * Create Request + * + * This overrides the parent createRequest function ensuring that the + * access token is passed along with the request data -- unless the + * request is a RestTokenRequest in which case no token is needed. If no + * token is available then a new one is created (e.g. if there has been no + * token request or the current token has expired). + * + * @param string $class + * @param array $parameters + * @return \Omnipay\PaidYET\Message\AbstractRestRequest + * + * public function createRequest($class, array $parameters = array()) + * { + * if (!$this->hasToken() && $class != '\Omnipay\PaidYET\Message\RestTokenRequest') { + * // This will set the internal token parameter which the parent + * // createRequest will find when it calls getParameters(). + * $this->getToken(true); + * } + * + * return parent::createRequest($class, $parameters); + * } + * + */ + + + /** + * Create a purchase request. + + * + * @link https://paidyet.readme.io/reference/post_transaction + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestPurchaseRequest + */ + public function purchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestPurchaseRequest', $parameters); + } + + /** + * Fetch a purchase request - Not used by PaidYET, placeholder. + * + * Use this call to get details about payments that have not completed, + * such as payments that are created and approved, or if a payment has failed. + * + * @link + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestFetchPurchaseRequest + */ + public function fetchPurchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestFetchPurchaseRequest', $parameters); + } + + + /** + * Completes a Sale (purchase) transaction. + * + * @link https://paidyet.readme.io/reference/post_transaction + * @param array $parameters + * @return Message\AbstractRestRequest + */ + public function completePurchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestCompletePurchaseRequest', $parameters); + } + + /** + * Create an authorization request. + * + * To collect payment at a later time, first authorize a payment using the /payment resource. + * You can then capture the payment to complete the sale and collect payment. + * + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestAuthorizeRequest + */ + public function authorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestAuthorizeRequest', $parameters); + } + + /** + * Void an authorization. + * + * @link https://paidyet.readme.io/reference/patch_transaction-id + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestVoidRequest + */ + public function void(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestVoidRequest', $parameters); + } + + /** + * Capture an authorization. + * + * The capture command moves an authorized transaction into the current batch for settlement. It is possible to capture + * an amount other than the one originally authorized, however, you must follow the guidelines established by the merchant + * service bank. Capturing a higher or lower dollar amount could result in additional penalties and fees. + * + * Most banks typically allow no more than 10 days to pass between the authorization/capture and settlement of a transaction. + * + * @link https://paidyet.readme.io/reference/put_transaction-id + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestCaptureRequest + */ + public function capture(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestCaptureRequest', $parameters); + } + + + + /** + * Retrieve Transaction + * + * Get a single transaction by its ID. + * + * + * @link https://paidyet.readme.io/reference/get_transaction-id + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestFetchTransactionRequest + */ + public function fetchTransaction(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestFetchTransactionRequest', $parameters); + } + + /** + * Refund a Sale Transaction + * + * A refund should be used once the transaction you are refunding has settled. If you are + * trying to cancel a transaction that is still in the currently open batch, you should use the + * void command instead. + * + * To refund a transaction that has been settled, you will pass in the transaction object + * with the type of 'refund', the original transaction id, and the amount you would like to + * refund. Most merchant accounts do not allow you to refund more than the original amount of the transaction. + * However, depending on the Credit Policy, a refund can be processed for larger than the original transaction amount. + * + * + * @link https://paidyet.readme.io/reference/post_transaction-id + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestRefundRequest + */ + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestRefundRequest', $parameters); + } + + /** + * Store a credit card in the vault + * + * + * @link https://paidyet.readme.io/reference/post_card + * @param array $parameters + * @return \Omnipay\PaidYET\Message\RestCreateCardRequest + */ + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestCreateCardRequest', $parameters); + } + + + + /** + * Search for transactions. + * + * Get a collection of transactions matching the supplied criteria. At least one parameter is required. + * + */ + public function searchTransaction(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaidYET\Message\RestSearchTransactionRequest', $parameters); + } + + +} From ad6157934ae0f21b7158f47db3f856f8a9cd04b2 Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 13 Jun 2024 15:21:51 -0700 Subject: [PATCH 02/14] add author --- composer.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index ad3e999a..c68ca8e8 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,8 @@ "license": "MIT", "authors": [ { - "name": "Adrian Macneil", - "email": "adrian@adrianmacneil.com" - }, - { - "name": "Barry vd. Heuvel", - "email": "barryvdh@gmail.com" + "name": "DeVaughn Skillern", + "email": "devaughn@paidyet.com" } ], "require": { From e7625655e0942b2539036590eb94a08a1283c0ab Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 13 Jun 2024 15:31:40 -0700 Subject: [PATCH 03/14] paidyet package funding --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 0d77ee1a..4f25eb2d 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1 @@ -github: [barryvdh] +github: [san0va] From 88393dd1d6a349d84ffc7fcb47933f95bc912216 Mon Sep 17 00:00:00 2001 From: san0va Date: Mon, 17 Jun 2024 08:50:30 -0700 Subject: [PATCH 04/14] intallation instructions update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e8b99b3..f448a83a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ 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`), From cd7bc9f047f55e48540bcc5bd6b877a4cb7f82f1 Mon Sep 17 00:00:00 2001 From: san0va Date: Wed, 19 Jun 2024 12:17:03 -0700 Subject: [PATCH 05/14] readme --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index f448a83a..b6af7dcd 100644 --- a/README.md +++ b/README.md @@ -72,12 +72,6 @@ For most uses, you will need to require `league/omnipay` and an individual gatew 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 From 13a91b90a3c39a93ed72f7b44b1d53d9f1bfa6f3 Mon Sep 17 00:00:00 2001 From: san0va Date: Wed, 19 Jun 2024 12:18:11 -0700 Subject: [PATCH 06/14] readme --- README.md | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/README.md b/README.md index b6af7dcd..5f257b10 100644 --- a/README.md +++ b/README.md @@ -19,50 +19,6 @@ 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/). From 455a485e253ae9c7074730563a31f51a5f49e032 Mon Sep 17 00:00:00 2001 From: san0va Date: Wed, 19 Jun 2024 12:24:25 -0700 Subject: [PATCH 07/14] readme changes --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index 5f257b10..d4aef347 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,6 @@ composer require paidyet/omnipay ``` -## 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 All payment gateways must implement [GatewayInterface](https://github.com/thephpleague/omnipay-common/blob/master/src/Common/GatewayInterface.php), and will usually From a9b565ac9b30e4a392f574b1410c733b0b0aca77 Mon Sep 17 00:00:00 2001 From: san0va Date: Tue, 25 Jun 2024 13:59:37 -0700 Subject: [PATCH 08/14] tests --- composer.json | 13 +- src/RestGateway.php | 6 - tests/RestGatewayTest.php | 244 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+), 8 deletions(-) create mode 100644 tests/RestGatewayTest.php diff --git a/composer.json b/composer.json index c68ca8e8..d1164865 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,9 @@ "email": "devaughn@paidyet.com" } ], + "autoload": { + "psr-4": { "Omnipay\\PaidYET\\" : "src/" } + }, "require": { "php": "^7.2|^8.0", "omnipay/common": "^3.1", @@ -26,7 +29,8 @@ "php-http/guzzle7-adapter": "^1" }, "require-dev": { - "omnipay/tests": "^3|^4" + "omnipay/tests": "^3|^4", + "http-interop/http-factory-guzzle": "^1.2" }, "autoload-dev": { "psr-4": { "Omnipay\\Tests\\" : "tests" } @@ -40,5 +44,10 @@ "test": "phpunit" }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "config": { + "allow-plugins": { + "php-http/discovery": true + } + } } diff --git a/src/RestGateway.php b/src/RestGateway.php index 545362ab..97e7d083 100644 --- a/src/RestGateway.php +++ b/src/RestGateway.php @@ -6,12 +6,6 @@ namespace Omnipay\PaidYET; use Omnipay\Common\AbstractGateway; -use Omnipay\PaidYET\Message\ProAuthorizeRequest; -use Omnipay\PaidYET\Message\CaptureRequest; -use Omnipay\PaidYET\Message\RefundRequest; -use Omnipay\PaidYET\Message\RestCreateWebhookRequest; -use Omnipay\PaidYET\Message\RestListWebhooksRequest; -use Omnipay\PaidYET\Message\RestVerifyWebhookSignatureRequest; /** * PaidYET Class using REST API diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php new file mode 100644 index 00000000..94764598 --- /dev/null +++ b/tests/RestGatewayTest.php @@ -0,0 +1,244 @@ +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', + 'card' => new CreditCard(array( + 'firstName' => 'Example', + 'lastName' => 'User', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => date('Y'), + 'cvv' => '123', + 'transactionID' => 'abc123', + )), + ); + + $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' => 'AUD', + )); + + $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); + } + +} \ No newline at end of file From bf0afe745e1b05c4aacff05a9f394a93df9257cf Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 27 Jun 2024 00:17:38 -0700 Subject: [PATCH 09/14] test --- src/Message/RestAuthorizeRequest.php | 2 +- tests/PaidyetOmnipayTest.php | 123 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 tests/PaidyetOmnipayTest.php diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index 5fb7bee7..bc70fd99 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -65,7 +65,7 @@ public function getData() $line2 = $this->getCard()->getAddress2(); } else { - $this->validate('amount', 'returnUrl', 'cancelUrl'); + $this->validate('amount'); unset($data['credit_card']); diff --git a/tests/PaidyetOmnipayTest.php b/tests/PaidyetOmnipayTest.php new file mode 100644 index 00000000..a7173962 --- /dev/null +++ b/tests/PaidyetOmnipayTest.php @@ -0,0 +1,123 @@ +mockHandler = new MockHandler(); + $handlerStack = HandlerStack::create($this->mockHandler); + $httpClient = new Client(['handler' => $handlerStack]); + + + // Create the Omnipay client with the mocked HTTP client + $omnipayClient = new OmnipayClient($httpClient); + $this->gateway = Omnipay::create('PaidYET_Rest', $omnipayClient); + $this->gateway->setSecret('XpzvQsVbZ4j16NxiRresU9YyM15ILPy9-RTXkPFs//t'); + + } + + public function testPurchaseSuccess() + { + $this->gateway->setTestMode(true); + + // Queue a successful response + $this->mockHandler->append(new Response(200, [], json_encode([ + 'result' => 'success', + 'amount' => '10.00', + 'token' => 'sample_token' + ]))); + + try { + $response = $this->gateway->purchase([ + 'amount' => '10.00', + 'currency' => 'USD', + 'credit_card' => [ + 'number' => '4242424242424242', + 'exp' => '06/2030', + 'cvv' => '123', + 'state' => 'CA' + ] + ])->send(); + + $this->assertTrue($response->isSuccessful()); + + //$data = json_decode($response->getData(), false); // Decode JSON response into an object + $data = json_decode($response->getData()->getContents(), false); + + // if (json_last_error() !== JSON_ERROR_NONE) { + // throw new \Exception('Invalid JSON response: ' . json_last_error_msg()); + // } + + // if (isset($data->result) && $data->result === 'success') { + // $this->assertTrue(true); + // $this->assertEquals('10.00', $data->amount); + // //$this->assertEquals('sample_token', $data->token); + // } elseif (isset($data->result) && $data->result === 'redirect') { + // // Handle redirection if necessary + // $this->markTestIncomplete('Redirection required.'); + // } else { + // $this->fail('Payment failed: ' . ($data->message ?? 'Unknown error')); + // } + } catch (\Exception $e) { + $this->fail('An unexpected error occurred: ' . $e->getMessage()); + } + } + + public function testPurchaseFailure() + { + $this->gateway->setTestMode(true); + + // Queue a failure response + $this->mockHandler->append(new Response(200, [], json_encode([ + 'result' => 'failure', + 'message' => 'Card declined' + ]))); + + try { + $response = $this->gateway->purchase([ + 'amount' => '10.00', + 'currency' => 'USD', + 'card' => [ + 'number' => '4000000000000002', // This card number should trigger a failure + 'expiryMonth' => '6', + 'expiryYear' => '2030', + 'cvv' => '123' + ] + ])->send(); + + $data = json_decode($response->getData(), false); // Decode JSON response into an object + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new \Exception('Invalid JSON response: ' . json_last_error_msg()); + } + + if (isset($data->result) && $data->result === 'success') { + $this->fail('Expected payment to fail, but it succeeded.'); + } elseif (isset($data->result) && $data->result === 'redirect') { + // Handle redirection if necessary + $this->markTestIncomplete('Redirection required.'); + } else { + $this->assertFalse($data->result === 'success'); + $this->assertNotEmpty($data->message ?? 'Unknown error'); + } + } catch (\Exception $e) { + $this->fail('An unexpected error occurred: ' . $e->getMessage()); + } + } +} \ No newline at end of file From 3d47cc423d6532d7f3425f6dc9877b8b84881ca4 Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 27 Jun 2024 04:00:31 -0700 Subject: [PATCH 10/14] simple test --- tests/RestGatewayTest.php | 259 +++++--------------------------------- 1 file changed, 31 insertions(+), 228 deletions(-) diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php index 94764598..5e7b275a 100644 --- a/tests/RestGatewayTest.php +++ b/tests/RestGatewayTest.php @@ -1,244 +1,47 @@ 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', - 'card' => new CreditCard(array( - 'firstName' => 'Example', - 'lastName' => 'User', - 'number' => '4111111111111111', - 'expiryMonth' => '12', - 'expiryYear' => date('Y'), - 'cvv' => '123', - 'transactionID' => 'abc123', - )), - ); - - $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' => 'AUD', - )); - - $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() +class SimpleTest extends TestCase +{ + protected $mockHandler; + + public function testMockResponse() { - $request = $this->gateway->listPurchase(array( - 'count' => 15, - 'startId' => 'PAY123', - 'startIndex' => 1, - 'startTime' => '2015-09-07T00:00:00Z', - 'endTime' => '2015-09-08T00:00:00Z', - )); + // Create a mock response + $mock = new MockHandler([ + new Response(200, ['Content-Type' => 'application/json'], json_encode(['status' => 'success', 'data' => 'mocked data'])) + ]); - $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'); + // Create a handler stack with the mock handler + $handlerStack = HandlerStack::create($mock); - $response = $this->gateway->createCard($this->options)->send(); + // Create a Guzzle client with the handler stack + $client = new OmnipayClient(['handler' => $handlerStack]); - $this->assertTrue($response->isSuccessful()); - $this->assertEquals('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference()); - $this->assertNull($response->getMessage()); - } + // Create an instance of the gateway + $gateway = new RestGateway($client); + // Set necessary parameters for the gateway + $gateway->setSecret('XpzvQsVbZ4j16NxiRresU9YyM15ILPy9-RTXkPFs '); + $gateway->setTestMode(true); - public function testPayWithSavedCard() - { - $this->setMockHttpResponse('RestCreateCardSuccess.txt'); - $response = $this->gateway->createCard($this->options)->send(); - $cardRef = $response->getCardReference(); + // Perform the request + $request = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', ]); + $response = $request->send(); - $this->setMockHttpResponse('RestPurchaseSuccess.txt'); - $response = $this->gateway->purchase(array('amount'=>'10.00', 'cardReference'=>$cardRef))->send(); + + // Assert the response $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); + $this->assertEquals('mocked data', $response->getData()['data']); } - } \ No newline at end of file From 7ad546e6e0eda6e3a26b7807d2379d0834ff663d Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 27 Jun 2024 04:03:44 -0700 Subject: [PATCH 11/14] test --- RestGatewayTest.php | 249 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 RestGatewayTest.php diff --git a/RestGatewayTest.php b/RestGatewayTest.php new file mode 100644 index 00000000..87b882b0 --- /dev/null +++ b/RestGatewayTest.php @@ -0,0 +1,249 @@ +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); + } + +} \ No newline at end of file From 793f1b187d92c139ac3a805e749981d52ee221d7 Mon Sep 17 00:00:00 2001 From: san0va Date: Thu, 27 Jun 2024 04:04:53 -0700 Subject: [PATCH 12/14] test --- tests/PaidyetOmnipayTest.php | 2 +- tests/RestGatewayTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PaidyetOmnipayTest.php b/tests/PaidyetOmnipayTest.php index a7173962..fd22bbcc 100644 --- a/tests/PaidyetOmnipayTest.php +++ b/tests/PaidyetOmnipayTest.php @@ -28,7 +28,7 @@ protected function setUp(): void // Create the Omnipay client with the mocked HTTP client $omnipayClient = new OmnipayClient($httpClient); $this->gateway = Omnipay::create('PaidYET_Rest', $omnipayClient); - $this->gateway->setSecret('XpzvQsVbZ4j16NxiRresU9YyM15ILPy9-RTXkPFs//t'); + $this->gateway->setSecret('your-api-key'); } diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php index 5e7b275a..68d29d88 100644 --- a/tests/RestGatewayTest.php +++ b/tests/RestGatewayTest.php @@ -32,7 +32,7 @@ public function testMockResponse() $gateway = new RestGateway($client); // Set necessary parameters for the gateway - $gateway->setSecret('XpzvQsVbZ4j16NxiRresU9YyM15ILPy9-RTXkPFs '); + $gateway->setSecret('Your-API-key'); $gateway->setTestMode(true); // Perform the request From 360d54041e98f93b1abaf0aca0758ab96cd2c41b Mon Sep 17 00:00:00 2001 From: san0va Date: Wed, 3 Jul 2024 01:42:53 -0700 Subject: [PATCH 13/14] tests --- .phpunit.result.cache | 1 + src/Message/AbstractRestRequest.php | 10 +- src/Message/RestAuthorizeResponse.php | 2 +- src/Message/RestPurchaseRequest.php | 1 + tests/PaidyetOmnipayTest.php | 123 -------------------- tests/RestGatewayTest.php | 159 ++++++++++++++++++++++---- 6 files changed, 148 insertions(+), 148 deletions(-) create mode 100644 .phpunit.result.cache delete mode 100644 tests/PaidyetOmnipayTest.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 00000000..d7db4fe7 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"Omnipay\\PaidYET\\RestGatewayTest::testBearerToken":4,"Omnipay\\PaidYET\\RestGatewayTest::testBearerTokenReused":4,"Omnipay\\PaidYET\\RestGatewayTest::testBearerTokenExpires":4,"Omnipay\\PaidYET\\RestGatewayTest::testAuthorize":4,"Omnipay\\PaidYET\\RestGatewayTest::testPurchase":4,"Omnipay\\PaidYET\\RestGatewayTest::testCapture":3,"Omnipay\\PaidYET\\RestGatewayTest::testRefund":3,"Omnipay\\PaidYET\\RestGatewayTest::testFullRefund":4,"Omnipay\\PaidYET\\RestGatewayTest::testFetchPurchase":4,"Omnipay\\PaidYET\\RestGatewayTest::testListPurchase":4,"Omnipay\\PaidYET\\RestGatewayTest::testCreateCard":4,"Omnipay\\PaidYET\\RestGatewayTest::testPayWithSavedCard":4,"Omnipay\\PaidYET\\RestGatewayTest::testRefundCapture":4,"Omnipay\\PaidYET\\RestGatewayTest::testVoid":3,"Omnipay\\PaidYET\\RestGatewayTest::testGetNameNotEmpty":4,"Omnipay\\PaidYET\\RestGatewayTest::testGetShortNameNotEmpty":4,"Omnipay\\PaidYET\\RestGatewayTest::testGetDefaultParametersReturnsArray":4,"Omnipay\\PaidYET\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":4,"Omnipay\\PaidYET\\RestGatewayTest::testTestMode":4,"Omnipay\\PaidYET\\RestGatewayTest::testCurrency":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsAuthorize":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCompleteAuthorize":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCapture":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsPurchase":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCompletePurchase":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsRefund":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsVoid":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCreateCard":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsDeleteCard":4,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsUpdateCard":4,"Omnipay\\PaidYET\\RestGatewayTest::testAuthorizeParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testCompleteAuthorizeParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testCaptureParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testPurchaseParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testCompletePurchaseParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testRefundParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testVoidParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testCreateCardParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testDeleteCardParameters":4,"Omnipay\\PaidYET\\RestGatewayTest::testUpdateCardParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testBearerToken":4,"PaidYET\\Omnipay\\RestGatewayTest::testBearerTokenReused":4,"PaidYET\\Omnipay\\RestGatewayTest::testBearerTokenExpires":4,"PaidYET\\Omnipay\\RestGatewayTest::testAuthorize":4,"PaidYET\\Omnipay\\RestGatewayTest::testPurchase":4,"PaidYET\\Omnipay\\RestGatewayTest::testCapture":4,"PaidYET\\Omnipay\\RestGatewayTest::testRefund":4,"PaidYET\\Omnipay\\RestGatewayTest::testFullRefund":4,"PaidYET\\Omnipay\\RestGatewayTest::testFetchPurchase":4,"PaidYET\\Omnipay\\RestGatewayTest::testListPurchase":4,"PaidYET\\Omnipay\\RestGatewayTest::testCreateCard":4,"PaidYET\\Omnipay\\RestGatewayTest::testPayWithSavedCard":4,"PaidYET\\Omnipay\\RestGatewayTest::testRefundCapture":4,"PaidYET\\Omnipay\\RestGatewayTest::testVoid":4,"PaidYET\\Omnipay\\RestGatewayTest::testGetNameNotEmpty":4,"PaidYET\\Omnipay\\RestGatewayTest::testGetShortNameNotEmpty":4,"PaidYET\\Omnipay\\RestGatewayTest::testGetDefaultParametersReturnsArray":4,"PaidYET\\Omnipay\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":4,"PaidYET\\Omnipay\\RestGatewayTest::testTestMode":4,"PaidYET\\Omnipay\\RestGatewayTest::testCurrency":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsAuthorize":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCompleteAuthorize":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCapture":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsPurchase":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCompletePurchase":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsRefund":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsVoid":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCreateCard":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsDeleteCard":4,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsUpdateCard":4,"PaidYET\\Omnipay\\RestGatewayTest::testAuthorizeParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testCompleteAuthorizeParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testCaptureParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testPurchaseParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testCompletePurchaseParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testRefundParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testVoidParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testCreateCardParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testDeleteCardParameters":4,"PaidYET\\Omnipay\\RestGatewayTest::testUpdateCardParameters":4,"Omnipay\\Test\\RestGatewayTest::testBearerToken":4,"Omnipay\\Test\\RestGatewayTest::testBearerTokenReused":4,"Omnipay\\Test\\RestGatewayTest::testBearerTokenExpires":4,"Omnipay\\Test\\RestGatewayTest::testAuthorize":4,"Omnipay\\Test\\RestGatewayTest::testPurchase":4,"Omnipay\\Test\\RestGatewayTest::testCapture":4,"Omnipay\\Test\\RestGatewayTest::testRefund":4,"Omnipay\\Test\\RestGatewayTest::testFullRefund":4,"Omnipay\\Test\\RestGatewayTest::testFetchPurchase":4,"Omnipay\\Test\\RestGatewayTest::testListPurchase":4,"Omnipay\\Test\\RestGatewayTest::testCreateCard":4,"Omnipay\\Test\\RestGatewayTest::testPayWithSavedCard":4,"Omnipay\\Test\\RestGatewayTest::testRefundCapture":4,"Omnipay\\Test\\RestGatewayTest::testVoid":4,"Omnipay\\Test\\RestGatewayTest::testGetNameNotEmpty":4,"Omnipay\\Test\\RestGatewayTest::testGetShortNameNotEmpty":4,"Omnipay\\Test\\RestGatewayTest::testGetDefaultParametersReturnsArray":4,"Omnipay\\Test\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":4,"Omnipay\\Test\\RestGatewayTest::testTestMode":4,"Omnipay\\Test\\RestGatewayTest::testCurrency":4,"Omnipay\\Test\\RestGatewayTest::testSupportsAuthorize":4,"Omnipay\\Test\\RestGatewayTest::testSupportsCompleteAuthorize":4,"Omnipay\\Test\\RestGatewayTest::testSupportsCapture":4,"Omnipay\\Test\\RestGatewayTest::testSupportsPurchase":4,"Omnipay\\Test\\RestGatewayTest::testSupportsCompletePurchase":4,"Omnipay\\Test\\RestGatewayTest::testSupportsRefund":4,"Omnipay\\Test\\RestGatewayTest::testSupportsVoid":4,"Omnipay\\Test\\RestGatewayTest::testSupportsCreateCard":4,"Omnipay\\Test\\RestGatewayTest::testSupportsDeleteCard":4,"Omnipay\\Test\\RestGatewayTest::testSupportsUpdateCard":4,"Omnipay\\Test\\RestGatewayTest::testAuthorizeParameters":4,"Omnipay\\Test\\RestGatewayTest::testCompleteAuthorizeParameters":4,"Omnipay\\Test\\RestGatewayTest::testCaptureParameters":4,"Omnipay\\Test\\RestGatewayTest::testPurchaseParameters":4,"Omnipay\\Test\\RestGatewayTest::testCompletePurchaseParameters":4,"Omnipay\\Test\\RestGatewayTest::testRefundParameters":4,"Omnipay\\Test\\RestGatewayTest::testVoidParameters":4,"Omnipay\\Test\\RestGatewayTest::testCreateCardParameters":4,"Omnipay\\Test\\RestGatewayTest::testDeleteCardParameters":4,"Omnipay\\Test\\RestGatewayTest::testUpdateCardParameters":4,"PaidYE\\Test\\RestGatewayTest::testBearerToken":4,"PaidYE\\Test\\RestGatewayTest::testBearerTokenReused":4,"PaidYE\\Test\\RestGatewayTest::testBearerTokenExpires":4,"PaidYE\\Test\\RestGatewayTest::testAuthorize":4,"PaidYE\\Test\\RestGatewayTest::testPurchase":4,"PaidYE\\Test\\RestGatewayTest::testCapture":4,"PaidYE\\Test\\RestGatewayTest::testRefund":4,"PaidYE\\Test\\RestGatewayTest::testFullRefund":4,"PaidYE\\Test\\RestGatewayTest::testFetchPurchase":4,"PaidYE\\Test\\RestGatewayTest::testListPurchase":4,"PaidYE\\Test\\RestGatewayTest::testCreateCard":4,"PaidYE\\Test\\RestGatewayTest::testPayWithSavedCard":4,"PaidYE\\Test\\RestGatewayTest::testRefundCapture":4,"PaidYE\\Test\\RestGatewayTest::testVoid":4,"PaidYE\\Test\\RestGatewayTest::testGetNameNotEmpty":4,"PaidYE\\Test\\RestGatewayTest::testGetShortNameNotEmpty":4,"PaidYE\\Test\\RestGatewayTest::testGetDefaultParametersReturnsArray":4,"PaidYE\\Test\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":4,"PaidYE\\Test\\RestGatewayTest::testTestMode":4,"PaidYE\\Test\\RestGatewayTest::testCurrency":4,"PaidYE\\Test\\RestGatewayTest::testSupportsAuthorize":4,"PaidYE\\Test\\RestGatewayTest::testSupportsCompleteAuthorize":4,"PaidYE\\Test\\RestGatewayTest::testSupportsCapture":4,"PaidYE\\Test\\RestGatewayTest::testSupportsPurchase":4,"PaidYE\\Test\\RestGatewayTest::testSupportsCompletePurchase":4,"PaidYE\\Test\\RestGatewayTest::testSupportsRefund":4,"PaidYE\\Test\\RestGatewayTest::testSupportsVoid":4,"PaidYE\\Test\\RestGatewayTest::testSupportsCreateCard":4,"PaidYE\\Test\\RestGatewayTest::testSupportsDeleteCard":4,"PaidYE\\Test\\RestGatewayTest::testSupportsUpdateCard":4,"PaidYE\\Test\\RestGatewayTest::testAuthorizeParameters":4,"PaidYE\\Test\\RestGatewayTest::testCompleteAuthorizeParameters":4,"PaidYE\\Test\\RestGatewayTest::testCaptureParameters":4,"PaidYE\\Test\\RestGatewayTest::testPurchaseParameters":4,"PaidYE\\Test\\RestGatewayTest::testCompletePurchaseParameters":4,"PaidYE\\Test\\RestGatewayTest::testRefundParameters":4,"PaidYE\\Test\\RestGatewayTest::testVoidParameters":4,"PaidYE\\Test\\RestGatewayTest::testCreateCardParameters":4,"PaidYE\\Test\\RestGatewayTest::testDeleteCardParameters":4,"PaidYE\\Test\\RestGatewayTest::testUpdateCardParameters":4,"PaidYET\\Test\\RestGatewayTest::testBearerToken":4,"PaidYET\\Test\\RestGatewayTest::testBearerTokenReused":4,"PaidYET\\Test\\RestGatewayTest::testBearerTokenExpires":4,"PaidYET\\Test\\RestGatewayTest::testAuthorize":4,"PaidYET\\Test\\RestGatewayTest::testPurchase":4,"PaidYET\\Test\\RestGatewayTest::testCapture":4,"PaidYET\\Test\\RestGatewayTest::testRefund":4,"PaidYET\\Test\\RestGatewayTest::testFullRefund":4,"PaidYET\\Test\\RestGatewayTest::testFetchPurchase":4,"PaidYET\\Test\\RestGatewayTest::testListPurchase":4,"PaidYET\\Test\\RestGatewayTest::testCreateCard":4,"PaidYET\\Test\\RestGatewayTest::testPayWithSavedCard":4,"PaidYET\\Test\\RestGatewayTest::testRefundCapture":4,"PaidYET\\Test\\RestGatewayTest::testVoid":4,"PaidYET\\Test\\RestGatewayTest::testGetNameNotEmpty":4,"PaidYET\\Test\\RestGatewayTest::testGetShortNameNotEmpty":4,"PaidYET\\Test\\RestGatewayTest::testGetDefaultParametersReturnsArray":4,"PaidYET\\Test\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":4,"PaidYET\\Test\\RestGatewayTest::testTestMode":4,"PaidYET\\Test\\RestGatewayTest::testCurrency":4,"PaidYET\\Test\\RestGatewayTest::testSupportsAuthorize":4,"PaidYET\\Test\\RestGatewayTest::testSupportsCompleteAuthorize":4,"PaidYET\\Test\\RestGatewayTest::testSupportsCapture":4,"PaidYET\\Test\\RestGatewayTest::testSupportsPurchase":4,"PaidYET\\Test\\RestGatewayTest::testSupportsCompletePurchase":4,"PaidYET\\Test\\RestGatewayTest::testSupportsRefund":4,"PaidYET\\Test\\RestGatewayTest::testSupportsVoid":4,"PaidYET\\Test\\RestGatewayTest::testSupportsCreateCard":4,"PaidYET\\Test\\RestGatewayTest::testSupportsDeleteCard":4,"PaidYET\\Test\\RestGatewayTest::testSupportsUpdateCard":4,"PaidYET\\Test\\RestGatewayTest::testAuthorizeParameters":4,"PaidYET\\Test\\RestGatewayTest::testCompleteAuthorizeParameters":4,"PaidYET\\Test\\RestGatewayTest::testCaptureParameters":4,"PaidYET\\Test\\RestGatewayTest::testPurchaseParameters":4,"PaidYET\\Test\\RestGatewayTest::testCompletePurchaseParameters":4,"PaidYET\\Test\\RestGatewayTest::testRefundParameters":4,"PaidYET\\Test\\RestGatewayTest::testVoidParameters":4,"PaidYET\\Test\\RestGatewayTest::testCreateCardParameters":4,"PaidYET\\Test\\RestGatewayTest::testDeleteCardParameters":4,"PaidYET\\Test\\RestGatewayTest::testUpdateCardParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testPurchaseSuccess":3,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testPurchaseFailure":3,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testGetNameNotEmpty":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testGetShortNameNotEmpty":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testGetDefaultParametersReturnsArray":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testDefaultParametersHaveMatchingMethods":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testTestMode":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCurrency":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsAuthorize":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCompleteAuthorize":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCapture":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsPurchase":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCompletePurchase":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsRefund":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsVoid":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCreateCard":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsDeleteCard":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsUpdateCard":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testAuthorizeParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCompleteAuthorizeParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCaptureParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testPurchaseParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCompletePurchaseParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testRefundParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testVoidParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCreateCardParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testDeleteCardParameters":4,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testUpdateCardParameters":4,"PaidYET\\Omnipay\\PaidyetOmnipayTest::testPurchaseSuccess":4,"PaidYET\\Omnipay\\PaidyetOmnipayTest::testPurchaseFailure":4,"PaidYET\\PaidyetOmnipayTest::testPurchaseSuccess":4,"PaidYET\\PaidyetOmnipayTest::testPurchaseFailure":4,"Omnipay\\PaidyetOmnipayTest::testPurchaseSuccess":4,"Omnipay\\PaidyetOmnipayTest::testPurchaseFailure":4,"PaidyetOmnipayTest::testPurchaseSuccess":4,"PaidyetOmnipayTest::testAuthorizeParameters":4,"PaidyetOmnipayTest::testCaptureParameters":4,"PaidyetOmnipayTest::testPurchaseParameters":4,"PaidyetOmnipayTest::testCompletePurchaseParameters":4,"PaidyetOmnipayTest::testRefundParameters":4,"PaidyetOmnipayTest::testVoidParameters":4,"PaidyetOmnipayTest::testCreateCardParameters":4,"PaidyetOmnipayTest::testPurchaseFailure":3,"PaidyetOmnipayTest::testGetNameNotEmpty":4,"PaidyetOmnipayTest::testGetShortNameNotEmpty":4,"PaidyetOmnipayTest::testGetDefaultParametersReturnsArray":4,"PaidyetOmnipayTest::testDefaultParametersHaveMatchingMethods":4,"PaidyetOmnipayTest::testTestMode":4,"PaidyetOmnipayTest::testCurrency":4,"PaidyetOmnipayTest::testSupportsAuthorize":4,"PaidyetOmnipayTest::testSupportsCompleteAuthorize":4,"PaidyetOmnipayTest::testSupportsCapture":4,"PaidyetOmnipayTest::testSupportsPurchase":4,"PaidyetOmnipayTest::testSupportsCompletePurchase":4,"PaidyetOmnipayTest::testSupportsRefund":4,"PaidyetOmnipayTest::testSupportsVoid":4,"PaidyetOmnipayTest::testSupportsCreateCard":4,"PaidyetOmnipayTest::testSupportsDeleteCard":4,"PaidyetOmnipayTest::testSupportsUpdateCard":4,"PaidyetOmnipayTest::testCompleteAuthorizeParameters":4,"PaidyetOmnipayTest::testDeleteCardParameters":4,"PaidyetOmnipayTest::testUpdateCardParameters":4,"SimpleTest::testMockResponse":3,"Omnipay\\PaidYET\\SimpleTest::testMockResponse":4,"SimpleTest::testGetNameNotEmpty":4,"SimpleTest::testGetShortNameNotEmpty":4,"SimpleTest::testGetDefaultParametersReturnsArray":4,"SimpleTest::testDefaultParametersHaveMatchingMethods":4,"SimpleTest::testTestMode":4,"SimpleTest::testCurrency":4,"SimpleTest::testSupportsAuthorize":4,"SimpleTest::testSupportsCompleteAuthorize":4,"SimpleTest::testSupportsCapture":4,"SimpleTest::testSupportsPurchase":4,"SimpleTest::testSupportsCompletePurchase":4,"SimpleTest::testSupportsRefund":4,"SimpleTest::testSupportsVoid":4,"SimpleTest::testSupportsCreateCard":4,"SimpleTest::testSupportsDeleteCard":4,"SimpleTest::testSupportsUpdateCard":4,"SimpleTest::testAuthorizeParameters":4,"SimpleTest::testCompleteAuthorizeParameters":4,"SimpleTest::testCaptureParameters":4,"SimpleTest::testPurchaseParameters":4,"SimpleTest::testCompletePurchaseParameters":4,"SimpleTest::testRefundParameters":4,"SimpleTest::testVoidParameters":4,"SimpleTest::testCreateCardParameters":4,"SimpleTest::testDeleteCardParameters":4,"SimpleTest::testUpdateCardParameters":4,"RestGatewayTest::testAuthorizeParameters":4,"RestGatewayTest::testCaptureParameters":4,"RestGatewayTest::testPurchaseParameters":4,"RestGatewayTest::testCompletePurchaseParameters":4,"RestGatewayTest::testRefundParameters":4,"RestGatewayTest::testVoidParameters":4,"RestGatewayTest::testCreateCardParameters":4,"RestGatewayTest::testFetchTransactionxx":4,"RestGatewayTest::testDeclinexx":3,"RestGatewayTest::testVoid":3,"RestGatewayTest::testVoidxx":3,"RestGatewayTest::testCreateCardxx":4,"RestGatewayTest::testRefundxx":3,"RestGatewayTest::testCapturexx":3},"times":{"Omnipay\\Tests\\OmnipayTest::testGetFactory":0.004,"Omnipay\\Tests\\OmnipayTest::testNewClient":0.002,"Omnipay\\PaidYET\\RestGatewayTest::testBearerToken":0.006,"Omnipay\\PaidYET\\RestGatewayTest::testBearerTokenReused":0,"Omnipay\\PaidYET\\RestGatewayTest::testBearerTokenExpires":0,"Omnipay\\PaidYET\\RestGatewayTest::testAuthorize":0.002,"Omnipay\\PaidYET\\RestGatewayTest::testPurchase":0,"Omnipay\\PaidYET\\RestGatewayTest::testCapture":0,"Omnipay\\PaidYET\\RestGatewayTest::testRefund":0,"Omnipay\\PaidYET\\RestGatewayTest::testFullRefund":0,"Omnipay\\PaidYET\\RestGatewayTest::testFetchPurchase":0,"Omnipay\\PaidYET\\RestGatewayTest::testListPurchase":0,"Omnipay\\PaidYET\\RestGatewayTest::testCreateCard":0,"Omnipay\\PaidYET\\RestGatewayTest::testPayWithSavedCard":0,"Omnipay\\PaidYET\\RestGatewayTest::testRefundCapture":0,"Omnipay\\PaidYET\\RestGatewayTest::testVoid":0,"Omnipay\\PaidYET\\RestGatewayTest::testGetNameNotEmpty":0,"Omnipay\\PaidYET\\RestGatewayTest::testGetShortNameNotEmpty":0,"Omnipay\\PaidYET\\RestGatewayTest::testGetDefaultParametersReturnsArray":0,"Omnipay\\PaidYET\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":0,"Omnipay\\PaidYET\\RestGatewayTest::testTestMode":0,"Omnipay\\PaidYET\\RestGatewayTest::testCurrency":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsAuthorize":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCompleteAuthorize":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCapture":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsPurchase":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCompletePurchase":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsRefund":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsVoid":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsCreateCard":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsDeleteCard":0,"Omnipay\\PaidYET\\RestGatewayTest::testSupportsUpdateCard":0,"Omnipay\\PaidYET\\RestGatewayTest::testAuthorizeParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testCompleteAuthorizeParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testCaptureParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testPurchaseParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testCompletePurchaseParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testRefundParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testVoidParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testCreateCardParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testDeleteCardParameters":0,"Omnipay\\PaidYET\\RestGatewayTest::testUpdateCardParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testBearerToken":0,"PaidYET\\Omnipay\\RestGatewayTest::testBearerTokenReused":0,"PaidYET\\Omnipay\\RestGatewayTest::testBearerTokenExpires":0,"PaidYET\\Omnipay\\RestGatewayTest::testAuthorize":0,"PaidYET\\Omnipay\\RestGatewayTest::testPurchase":0,"PaidYET\\Omnipay\\RestGatewayTest::testCapture":0,"PaidYET\\Omnipay\\RestGatewayTest::testRefund":0,"PaidYET\\Omnipay\\RestGatewayTest::testFullRefund":0,"PaidYET\\Omnipay\\RestGatewayTest::testFetchPurchase":0,"PaidYET\\Omnipay\\RestGatewayTest::testListPurchase":0,"PaidYET\\Omnipay\\RestGatewayTest::testCreateCard":0,"PaidYET\\Omnipay\\RestGatewayTest::testPayWithSavedCard":0,"PaidYET\\Omnipay\\RestGatewayTest::testRefundCapture":0,"PaidYET\\Omnipay\\RestGatewayTest::testVoid":0,"PaidYET\\Omnipay\\RestGatewayTest::testGetNameNotEmpty":0,"PaidYET\\Omnipay\\RestGatewayTest::testGetShortNameNotEmpty":0,"PaidYET\\Omnipay\\RestGatewayTest::testGetDefaultParametersReturnsArray":0,"PaidYET\\Omnipay\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":0,"PaidYET\\Omnipay\\RestGatewayTest::testTestMode":0,"PaidYET\\Omnipay\\RestGatewayTest::testCurrency":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsAuthorize":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCompleteAuthorize":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCapture":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsPurchase":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCompletePurchase":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsRefund":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsVoid":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsCreateCard":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsDeleteCard":0,"PaidYET\\Omnipay\\RestGatewayTest::testSupportsUpdateCard":0,"PaidYET\\Omnipay\\RestGatewayTest::testAuthorizeParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testCompleteAuthorizeParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testCaptureParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testPurchaseParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testCompletePurchaseParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testRefundParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testVoidParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testCreateCardParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testDeleteCardParameters":0,"PaidYET\\Omnipay\\RestGatewayTest::testUpdateCardParameters":0,"Omnipay\\Test\\RestGatewayTest::testBearerToken":0,"Omnipay\\Test\\RestGatewayTest::testBearerTokenReused":0,"Omnipay\\Test\\RestGatewayTest::testBearerTokenExpires":0,"Omnipay\\Test\\RestGatewayTest::testAuthorize":0,"Omnipay\\Test\\RestGatewayTest::testPurchase":0,"Omnipay\\Test\\RestGatewayTest::testCapture":0,"Omnipay\\Test\\RestGatewayTest::testRefund":0,"Omnipay\\Test\\RestGatewayTest::testFullRefund":0,"Omnipay\\Test\\RestGatewayTest::testFetchPurchase":0,"Omnipay\\Test\\RestGatewayTest::testListPurchase":0,"Omnipay\\Test\\RestGatewayTest::testCreateCard":0,"Omnipay\\Test\\RestGatewayTest::testPayWithSavedCard":0,"Omnipay\\Test\\RestGatewayTest::testRefundCapture":0,"Omnipay\\Test\\RestGatewayTest::testVoid":0,"Omnipay\\Test\\RestGatewayTest::testGetNameNotEmpty":0,"Omnipay\\Test\\RestGatewayTest::testGetShortNameNotEmpty":0,"Omnipay\\Test\\RestGatewayTest::testGetDefaultParametersReturnsArray":0,"Omnipay\\Test\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":0,"Omnipay\\Test\\RestGatewayTest::testTestMode":0,"Omnipay\\Test\\RestGatewayTest::testCurrency":0,"Omnipay\\Test\\RestGatewayTest::testSupportsAuthorize":0,"Omnipay\\Test\\RestGatewayTest::testSupportsCompleteAuthorize":0,"Omnipay\\Test\\RestGatewayTest::testSupportsCapture":0,"Omnipay\\Test\\RestGatewayTest::testSupportsPurchase":0,"Omnipay\\Test\\RestGatewayTest::testSupportsCompletePurchase":0,"Omnipay\\Test\\RestGatewayTest::testSupportsRefund":0,"Omnipay\\Test\\RestGatewayTest::testSupportsVoid":0,"Omnipay\\Test\\RestGatewayTest::testSupportsCreateCard":0,"Omnipay\\Test\\RestGatewayTest::testSupportsDeleteCard":0,"Omnipay\\Test\\RestGatewayTest::testSupportsUpdateCard":0,"Omnipay\\Test\\RestGatewayTest::testAuthorizeParameters":0,"Omnipay\\Test\\RestGatewayTest::testCompleteAuthorizeParameters":0,"Omnipay\\Test\\RestGatewayTest::testCaptureParameters":0,"Omnipay\\Test\\RestGatewayTest::testPurchaseParameters":0,"Omnipay\\Test\\RestGatewayTest::testCompletePurchaseParameters":0,"Omnipay\\Test\\RestGatewayTest::testRefundParameters":0,"Omnipay\\Test\\RestGatewayTest::testVoidParameters":0,"Omnipay\\Test\\RestGatewayTest::testCreateCardParameters":0,"Omnipay\\Test\\RestGatewayTest::testDeleteCardParameters":0,"Omnipay\\Test\\RestGatewayTest::testUpdateCardParameters":0,"PaidYE\\Test\\RestGatewayTest::testBearerToken":0,"PaidYE\\Test\\RestGatewayTest::testBearerTokenReused":0,"PaidYE\\Test\\RestGatewayTest::testBearerTokenExpires":0,"PaidYE\\Test\\RestGatewayTest::testAuthorize":0,"PaidYE\\Test\\RestGatewayTest::testPurchase":0,"PaidYE\\Test\\RestGatewayTest::testCapture":0,"PaidYE\\Test\\RestGatewayTest::testRefund":0,"PaidYE\\Test\\RestGatewayTest::testFullRefund":0,"PaidYE\\Test\\RestGatewayTest::testFetchPurchase":0,"PaidYE\\Test\\RestGatewayTest::testListPurchase":0,"PaidYE\\Test\\RestGatewayTest::testCreateCard":0,"PaidYE\\Test\\RestGatewayTest::testPayWithSavedCard":0,"PaidYE\\Test\\RestGatewayTest::testRefundCapture":0,"PaidYE\\Test\\RestGatewayTest::testVoid":0,"PaidYE\\Test\\RestGatewayTest::testGetNameNotEmpty":0,"PaidYE\\Test\\RestGatewayTest::testGetShortNameNotEmpty":0,"PaidYE\\Test\\RestGatewayTest::testGetDefaultParametersReturnsArray":0,"PaidYE\\Test\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":0,"PaidYE\\Test\\RestGatewayTest::testTestMode":0,"PaidYE\\Test\\RestGatewayTest::testCurrency":0,"PaidYE\\Test\\RestGatewayTest::testSupportsAuthorize":0,"PaidYE\\Test\\RestGatewayTest::testSupportsCompleteAuthorize":0,"PaidYE\\Test\\RestGatewayTest::testSupportsCapture":0,"PaidYE\\Test\\RestGatewayTest::testSupportsPurchase":0,"PaidYE\\Test\\RestGatewayTest::testSupportsCompletePurchase":0,"PaidYE\\Test\\RestGatewayTest::testSupportsRefund":0,"PaidYE\\Test\\RestGatewayTest::testSupportsVoid":0,"PaidYE\\Test\\RestGatewayTest::testSupportsCreateCard":0,"PaidYE\\Test\\RestGatewayTest::testSupportsDeleteCard":0,"PaidYE\\Test\\RestGatewayTest::testSupportsUpdateCard":0,"PaidYE\\Test\\RestGatewayTest::testAuthorizeParameters":0,"PaidYE\\Test\\RestGatewayTest::testCompleteAuthorizeParameters":0,"PaidYE\\Test\\RestGatewayTest::testCaptureParameters":0,"PaidYE\\Test\\RestGatewayTest::testPurchaseParameters":0,"PaidYE\\Test\\RestGatewayTest::testCompletePurchaseParameters":0,"PaidYE\\Test\\RestGatewayTest::testRefundParameters":0,"PaidYE\\Test\\RestGatewayTest::testVoidParameters":0,"PaidYE\\Test\\RestGatewayTest::testCreateCardParameters":0,"PaidYE\\Test\\RestGatewayTest::testDeleteCardParameters":0,"PaidYE\\Test\\RestGatewayTest::testUpdateCardParameters":0,"PaidYET\\Test\\RestGatewayTest::testBearerToken":0,"PaidYET\\Test\\RestGatewayTest::testBearerTokenReused":0,"PaidYET\\Test\\RestGatewayTest::testBearerTokenExpires":0,"PaidYET\\Test\\RestGatewayTest::testAuthorize":0,"PaidYET\\Test\\RestGatewayTest::testPurchase":0,"PaidYET\\Test\\RestGatewayTest::testCapture":0,"PaidYET\\Test\\RestGatewayTest::testRefund":0,"PaidYET\\Test\\RestGatewayTest::testFullRefund":0,"PaidYET\\Test\\RestGatewayTest::testFetchPurchase":0,"PaidYET\\Test\\RestGatewayTest::testListPurchase":0,"PaidYET\\Test\\RestGatewayTest::testCreateCard":0,"PaidYET\\Test\\RestGatewayTest::testPayWithSavedCard":0,"PaidYET\\Test\\RestGatewayTest::testRefundCapture":0,"PaidYET\\Test\\RestGatewayTest::testVoid":0,"PaidYET\\Test\\RestGatewayTest::testGetNameNotEmpty":0,"PaidYET\\Test\\RestGatewayTest::testGetShortNameNotEmpty":0,"PaidYET\\Test\\RestGatewayTest::testGetDefaultParametersReturnsArray":0,"PaidYET\\Test\\RestGatewayTest::testDefaultParametersHaveMatchingMethods":0,"PaidYET\\Test\\RestGatewayTest::testTestMode":0,"PaidYET\\Test\\RestGatewayTest::testCurrency":0,"PaidYET\\Test\\RestGatewayTest::testSupportsAuthorize":0,"PaidYET\\Test\\RestGatewayTest::testSupportsCompleteAuthorize":0,"PaidYET\\Test\\RestGatewayTest::testSupportsCapture":0,"PaidYET\\Test\\RestGatewayTest::testSupportsPurchase":0,"PaidYET\\Test\\RestGatewayTest::testSupportsCompletePurchase":0,"PaidYET\\Test\\RestGatewayTest::testSupportsRefund":0,"PaidYET\\Test\\RestGatewayTest::testSupportsVoid":0,"PaidYET\\Test\\RestGatewayTest::testSupportsCreateCard":0,"PaidYET\\Test\\RestGatewayTest::testSupportsDeleteCard":0,"PaidYET\\Test\\RestGatewayTest::testSupportsUpdateCard":0,"PaidYET\\Test\\RestGatewayTest::testAuthorizeParameters":0,"PaidYET\\Test\\RestGatewayTest::testCompleteAuthorizeParameters":0,"PaidYET\\Test\\RestGatewayTest::testCaptureParameters":0,"PaidYET\\Test\\RestGatewayTest::testPurchaseParameters":0,"PaidYET\\Test\\RestGatewayTest::testCompletePurchaseParameters":0,"PaidYET\\Test\\RestGatewayTest::testRefundParameters":0,"PaidYET\\Test\\RestGatewayTest::testVoidParameters":0,"PaidYET\\Test\\RestGatewayTest::testCreateCardParameters":0,"PaidYET\\Test\\RestGatewayTest::testDeleteCardParameters":0,"PaidYET\\Test\\RestGatewayTest::testUpdateCardParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testPurchaseSuccess":0.007,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testPurchaseFailure":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testGetNameNotEmpty":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testGetShortNameNotEmpty":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testGetDefaultParametersReturnsArray":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testDefaultParametersHaveMatchingMethods":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testTestMode":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCurrency":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsAuthorize":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCompleteAuthorize":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCapture":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsPurchase":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCompletePurchase":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsRefund":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsVoid":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsCreateCard":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsDeleteCard":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testSupportsUpdateCard":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testAuthorizeParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCompleteAuthorizeParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCaptureParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testPurchaseParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCompletePurchaseParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testRefundParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testVoidParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testCreateCardParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testDeleteCardParameters":0,"Omnipay\\PaidYET\\PaidyetOmnipayTest::testUpdateCardParameters":0,"PaidYET\\Omnipay\\PaidyetOmnipayTest::testPurchaseSuccess":0,"PaidYET\\Omnipay\\PaidyetOmnipayTest::testPurchaseFailure":0,"PaidYET\\PaidyetOmnipayTest::testPurchaseSuccess":0,"PaidYET\\PaidyetOmnipayTest::testPurchaseFailure":0,"Omnipay\\PaidyetOmnipayTest::testPurchaseSuccess":0.001,"Omnipay\\PaidyetOmnipayTest::testPurchaseFailure":0,"PaidyetOmnipayTest::testPurchaseSuccess":0.01,"PaidyetOmnipayTest::testGetNameNotEmpty":0,"PaidyetOmnipayTest::testGetShortNameNotEmpty":0,"PaidyetOmnipayTest::testGetDefaultParametersReturnsArray":0,"PaidyetOmnipayTest::testDefaultParametersHaveMatchingMethods":0,"PaidyetOmnipayTest::testTestMode":0,"PaidyetOmnipayTest::testCurrency":0,"PaidyetOmnipayTest::testSupportsAuthorize":0,"PaidyetOmnipayTest::testSupportsCompleteAuthorize":0,"PaidyetOmnipayTest::testSupportsCapture":0,"PaidyetOmnipayTest::testSupportsPurchase":0,"PaidyetOmnipayTest::testSupportsCompletePurchase":0,"PaidyetOmnipayTest::testSupportsRefund":0,"PaidyetOmnipayTest::testSupportsVoid":0,"PaidyetOmnipayTest::testSupportsCreateCard":0,"PaidyetOmnipayTest::testSupportsDeleteCard":0,"PaidyetOmnipayTest::testSupportsUpdateCard":0,"PaidyetOmnipayTest::testAuthorizeParameters":0,"PaidyetOmnipayTest::testCompleteAuthorizeParameters":0,"PaidyetOmnipayTest::testCaptureParameters":0,"PaidyetOmnipayTest::testPurchaseParameters":0,"PaidyetOmnipayTest::testCompletePurchaseParameters":0,"PaidyetOmnipayTest::testRefundParameters":0,"PaidyetOmnipayTest::testVoidParameters":0,"PaidyetOmnipayTest::testCreateCardParameters":0,"PaidyetOmnipayTest::testDeleteCardParameters":0,"PaidyetOmnipayTest::testUpdateCardParameters":0,"PaidyetOmnipayTest::testPurchaseFailure":0.001,"SimpleTest::testMockResponse":0.006,"Omnipay\\PaidYET\\SimpleTest::testMockResponse":0,"SimpleTest::testGetNameNotEmpty":0,"SimpleTest::testGetShortNameNotEmpty":0,"SimpleTest::testGetDefaultParametersReturnsArray":0,"SimpleTest::testDefaultParametersHaveMatchingMethods":0,"SimpleTest::testTestMode":0,"SimpleTest::testCurrency":0,"SimpleTest::testSupportsAuthorize":0,"SimpleTest::testSupportsCompleteAuthorize":0,"SimpleTest::testSupportsCapture":0,"SimpleTest::testSupportsPurchase":0,"SimpleTest::testSupportsCompletePurchase":0,"SimpleTest::testSupportsRefund":0,"SimpleTest::testSupportsVoid":0,"SimpleTest::testSupportsCreateCard":0,"SimpleTest::testSupportsDeleteCard":0,"SimpleTest::testSupportsUpdateCard":0,"SimpleTest::testAuthorizeParameters":0,"SimpleTest::testCompleteAuthorizeParameters":0,"SimpleTest::testCaptureParameters":0,"SimpleTest::testPurchaseParameters":0,"SimpleTest::testCompletePurchaseParameters":0,"SimpleTest::testRefundParameters":0,"SimpleTest::testVoidParameters":0,"SimpleTest::testCreateCardParameters":0,"SimpleTest::testDeleteCardParameters":0,"SimpleTest::testUpdateCardParameters":0,"SimpleTest::testFetchTransaction":0,"RestGatewayTest::testMockResponse":0.01,"RestGatewayTest::testFetchTransaction":0,"RestGatewayTest::testGetNameNotEmpty":0,"RestGatewayTest::testGetShortNameNotEmpty":0,"RestGatewayTest::testGetDefaultParametersReturnsArray":0,"RestGatewayTest::testDefaultParametersHaveMatchingMethods":0,"RestGatewayTest::testTestMode":0,"RestGatewayTest::testCurrency":0,"RestGatewayTest::testSupportsAuthorize":0,"RestGatewayTest::testSupportsCompleteAuthorize":0,"RestGatewayTest::testSupportsCapture":0,"RestGatewayTest::testSupportsPurchase":0,"RestGatewayTest::testSupportsCompletePurchase":0,"RestGatewayTest::testSupportsRefund":0,"RestGatewayTest::testSupportsVoid":0,"RestGatewayTest::testSupportsCreateCard":0,"RestGatewayTest::testSupportsDeleteCard":0,"RestGatewayTest::testSupportsUpdateCard":0,"RestGatewayTest::testAuthorizeParameters":0.001,"RestGatewayTest::testCompleteAuthorizeParameters":0,"RestGatewayTest::testCaptureParameters":0,"RestGatewayTest::testPurchaseParameters":0,"RestGatewayTest::testCompletePurchaseParameters":0,"RestGatewayTest::testRefundParameters":0,"RestGatewayTest::testVoidParameters":0,"RestGatewayTest::testCreateCardParameters":0,"RestGatewayTest::testDeleteCardParameters":0,"RestGatewayTest::testUpdateCardParameters":0,"RestGatewayTest::testMockResponsexx":0.013,"RestGatewayTest::testFetchTransactionxx":0.001,"RestGatewayTest::testDeclinexx":0,"RestGatewayTest::testVoid":0.001,"RestGatewayTest::testVoidxx":0.001,"RestGatewayTest::testPurchasexx":0.009,"RestGatewayTest::testCreateCardxx":0.002,"RestGatewayTest::testRefundxx":0,"RestGatewayTest::testCapturexx":0}} \ No newline at end of file diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php index 300ef88b..e5501209 100644 --- a/src/Message/AbstractRestRequest.php +++ b/src/Message/AbstractRestRequest.php @@ -131,7 +131,7 @@ public function setPayerId($value) return $this->setParameter('payerId', $value); } - /** + /** * Get HTTP Method. * * This is nearly always POST but can be over-ridden in sub classes. @@ -159,7 +159,7 @@ protected function getLoginEndpoint() public function sendData($data) { - + // Guzzle HTTP Client createRequest does funny things when a GET request // has attached data, so don't send the data if the method is GET. if ($this->getHttpMethod() == 'GET') { @@ -175,13 +175,16 @@ public function sendData($data) // Print token: //print_r($this->getToken()); //exit(); + + $token = $this->getParameter('token'); + try { $httpResponse = $this->httpClient->request( $this->getHttpMethod(), $this->getEndpoint(), array( 'Accept' => 'application/json', - 'Authorization' => 'Bearer ' . $this->getToken(), + 'Authorization' => 'Bearer ' . $token, 'Content-type' => 'application/json', ), $body @@ -193,6 +196,7 @@ public function sendData($data) //exit(); return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); } catch (\Exception $e) { + throw $e; throw new InvalidResponseException( 'Error communicating with payment gateway: ' . $e->getMessage(), $e->getCode() diff --git a/src/Message/RestAuthorizeResponse.php b/src/Message/RestAuthorizeResponse.php index d726be6d..606bb95a 100644 --- a/src/Message/RestAuthorizeResponse.php +++ b/src/Message/RestAuthorizeResponse.php @@ -14,7 +14,7 @@ class RestAuthorizeResponse extends RestResponse implements RedirectResponseInte { public function isSuccessful() { - return empty($this->data['error']) && $this->getCode() == 201; + return empty($this->data['error']) && $this->getCode() >= 200 && $this->getCode() <300; } public function isRedirect() diff --git a/src/Message/RestPurchaseRequest.php b/src/Message/RestPurchaseRequest.php index 35e192ae..d95fc92c 100644 --- a/src/Message/RestPurchaseRequest.php +++ b/src/Message/RestPurchaseRequest.php @@ -18,4 +18,5 @@ public function getData() $data['type'] = 'sale'; return $data; } + } diff --git a/tests/PaidyetOmnipayTest.php b/tests/PaidyetOmnipayTest.php deleted file mode 100644 index fd22bbcc..00000000 --- a/tests/PaidyetOmnipayTest.php +++ /dev/null @@ -1,123 +0,0 @@ -mockHandler = new MockHandler(); - $handlerStack = HandlerStack::create($this->mockHandler); - $httpClient = new Client(['handler' => $handlerStack]); - - - // Create the Omnipay client with the mocked HTTP client - $omnipayClient = new OmnipayClient($httpClient); - $this->gateway = Omnipay::create('PaidYET_Rest', $omnipayClient); - $this->gateway->setSecret('your-api-key'); - - } - - public function testPurchaseSuccess() - { - $this->gateway->setTestMode(true); - - // Queue a successful response - $this->mockHandler->append(new Response(200, [], json_encode([ - 'result' => 'success', - 'amount' => '10.00', - 'token' => 'sample_token' - ]))); - - try { - $response = $this->gateway->purchase([ - 'amount' => '10.00', - 'currency' => 'USD', - 'credit_card' => [ - 'number' => '4242424242424242', - 'exp' => '06/2030', - 'cvv' => '123', - 'state' => 'CA' - ] - ])->send(); - - $this->assertTrue($response->isSuccessful()); - - //$data = json_decode($response->getData(), false); // Decode JSON response into an object - $data = json_decode($response->getData()->getContents(), false); - - // if (json_last_error() !== JSON_ERROR_NONE) { - // throw new \Exception('Invalid JSON response: ' . json_last_error_msg()); - // } - - // if (isset($data->result) && $data->result === 'success') { - // $this->assertTrue(true); - // $this->assertEquals('10.00', $data->amount); - // //$this->assertEquals('sample_token', $data->token); - // } elseif (isset($data->result) && $data->result === 'redirect') { - // // Handle redirection if necessary - // $this->markTestIncomplete('Redirection required.'); - // } else { - // $this->fail('Payment failed: ' . ($data->message ?? 'Unknown error')); - // } - } catch (\Exception $e) { - $this->fail('An unexpected error occurred: ' . $e->getMessage()); - } - } - - public function testPurchaseFailure() - { - $this->gateway->setTestMode(true); - - // Queue a failure response - $this->mockHandler->append(new Response(200, [], json_encode([ - 'result' => 'failure', - 'message' => 'Card declined' - ]))); - - try { - $response = $this->gateway->purchase([ - 'amount' => '10.00', - 'currency' => 'USD', - 'card' => [ - 'number' => '4000000000000002', // This card number should trigger a failure - 'expiryMonth' => '6', - 'expiryYear' => '2030', - 'cvv' => '123' - ] - ])->send(); - - $data = json_decode($response->getData(), false); // Decode JSON response into an object - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new \Exception('Invalid JSON response: ' . json_last_error_msg()); - } - - if (isset($data->result) && $data->result === 'success') { - $this->fail('Expected payment to fail, but it succeeded.'); - } elseif (isset($data->result) && $data->result === 'redirect') { - // Handle redirection if necessary - $this->markTestIncomplete('Redirection required.'); - } else { - $this->assertFalse($data->result === 'success'); - $this->assertNotEmpty($data->message ?? 'Unknown error'); - } - } catch (\Exception $e) { - $this->fail('An unexpected error occurred: ' . $e->getMessage()); - } - } -} \ No newline at end of file diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php index 68d29d88..a953a690 100644 --- a/tests/RestGatewayTest.php +++ b/tests/RestGatewayTest.php @@ -1,47 +1,164 @@ 'application/json'], json_encode(['status' => 'success', 'data' => 'mocked data'])) - ]); + public $options; - // Create a handler stack with the mock handler - $handlerStack = HandlerStack::create($mock); + public function setUp():void + { + + parent::setUp(); - // Create a Guzzle client with the handler stack - $client = new OmnipayClient(['handler' => $handlerStack]); + $this->gateway = new RestGateway($this->getHttpClient(), $this->getHttpRequest()); + $this->gateway->setToken('token123'); + $this->gateway->setTokenExpires(time()+600); + } + + public function testPurchasexx() + { + $this->gateway->setToken('token123'); + $this->gateway->setTokenExpires(time()+600); // Create an instance of the gateway - $gateway = new RestGateway($client); + //$this->gateway = new RestGateway($client); // Set necessary parameters for the gateway - $gateway->setSecret('Your-API-key'); - $gateway->setTestMode(true); + + $this->gateway->setSecret('Your-API-key'); + $this->gateway->setTestMode(true); // Perform the request - $request = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', ]); + $this->setMockHttpResponse('RestPurchaseSuccess.txt'); + $request = $this->gateway->purchase(['amount' => '10.00', 'currency' => 'USD' ]); $response = $request->send(); - // Assert the response + //$this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertTrue($response->isSuccessful()); + //var_dump($response); + //exit(get_class($response)); + //$this->assertEquals('mocked data', $response->getData()['data']); + } + + public function testFetchTransactionxx() + { + $this->gateway->setToken('token123'); + $this->gateway->setTokenExpires(time()+600); + + // Perform the request + $this->setMockHttpResponse('RestFetchPurchaseSuccess.txt'); + + $request = $this->gateway->fetchTransaction(array('transactionReference' => 'abc123')); + $response = $request->send(); + $this->assertTrue($response->isSuccessful()); + + } + + public function testDeclinexx() + { + $this->gateway->setToken('token123'); + $this->gateway->setTokenExpires(time()+600); + + // Perform the request + $this->setMockHttpResponse('RestDeclineTransaction.txt'); + $request = $this->gateway->purchase(['amount' => '10.00', 'currency' => 'USD' ]); + $response = $request->send(); + //var_dump(get_class($response)); + + $this->assertTrue($response->isSuccessful(), "declined transaction was marked as successful."); + + } + + public function testVoidxx() + { + $this->gateway->setToken('token123'); + $this->gateway->setTokenExpires(time()+600); + $this->gateway->setTestMode(true); + + $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.sandbox-paidyet.com/v3/transaction/', $endPoint); + $data = $request->getData(); + $this->assertNotEmpty($data); + } + + public function testCreateCardxx() + { + $this->gateway->setToken('token123'); + $this->gateway->setTokenExpires(time()+600); + $this->gateway->setTestMode(true); + + + //Todo: combine first and last name fields and expiry fields + $this->options = array( + 'amount' => '10.00', + 'card' => new CreditCard(array( + 'firstName' => 'Example', + 'lastName' => 'User', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => date('Y'), + 'cvv' => '123', + )), + ); + + $this->setMockHttpResponse('RestCreateCardSuccess.txt'); + + $response = $this->gateway->createCard($this->options)->send(); + $this->assertTrue($response->isSuccessful()); - $this->assertEquals('mocked data', $response->getData()['data']); + $this->assertEquals('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference()); + $this->assertNull($response->getMessage()); + } + + public function testRefundxx() + { + $this->gateway->setTestMode(true); + + $request = $this->gateway->refund(array( + 'transactionID' => 'abc123', + 'amount' => 10.00, + )); + + $this->assertInstanceOf('\Omnipay\PaidYET\Message\RestRefundRequest', $request); + $this->assertSame('abc123', $request->getTransactionID()); + $endPoint = $request->getEndpoint(); + $this->assertSame('https://api.sandbox-paidyet.com/v3/transaction/abc123', $endPoint); + $data = $request->getData(); + $this->assertNotEmpty($data); + } + + public function testCapturexx() + { + $this->gateway->setTestMode(true); + + $request = $this->gateway->capture(array( + 'transactionID' => 'abc123', + 'amount' => 10.00, + )); + + $this->assertInstanceOf('\Omnipay\PaidYET\Message\RestCaptureRequest', $request); + $this->assertSame('abc123', $request->getTransactionID()); + $endPoint = $request->getEndpoint(); + $this->assertSame('https://api.sandbox-paidyet.com/v3/transaction/abc123', $endPoint); + $data = $request->getData(); + $this->assertNotEmpty($data); } } \ No newline at end of file From 63e234b773cfa62c14e13d99eb5a233e5f0640a2 Mon Sep 17 00:00:00 2001 From: san0va Date: Wed, 3 Jul 2024 01:44:46 -0700 Subject: [PATCH 14/14] test --- tests/RestGatewayTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php index a953a690..6f6226b4 100644 --- a/tests/RestGatewayTest.php +++ b/tests/RestGatewayTest.php @@ -1,13 +1,7 @@