From a32409907f0215f8a82c06f027b8e684d09ef79d Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:03:22 -0500 Subject: [PATCH 01/17] Update makefile with new target --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 511cb81..962afc9 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ test: psalm: vendor/bin/psalm +check: + vendor/bin/psalm && vendor/bin/phpunit + # Install install: install_with_psalm From f02a8af28dcf5f72cadf12213d9f5ea05bf807aa Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:05:56 -0500 Subject: [PATCH 02/17] Revert "Psalm fixes for StringChecker" This reverts commit bc6cea37 --- psalm_plugins/StringChecker.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/psalm_plugins/StringChecker.php b/psalm_plugins/StringChecker.php index e29f41a..60f9430 100644 --- a/psalm_plugins/StringChecker.php +++ b/psalm_plugins/StringChecker.php @@ -16,7 +16,7 @@ class StringChecker extends \Psalm\Plugin * Checks an expression * * @param StatementsChecker $statements_checker - * @param PhpParser\Node\Expr $stmt + * @param \PhpParser\Node\Expr $stmt * @param Context $context * @param CodeLocation $code_location * @param array $suppressed_issues @@ -24,7 +24,7 @@ class StringChecker extends \Psalm\Plugin */ public function checkExpression( StatementsChecker $statements_checker, - PhpParser\Node\Expr $stmt, + \PhpParser\Node\Expr $stmt, Context $context, CodeLocation $code_location, array $suppressed_issues @@ -37,7 +37,7 @@ public function checkExpression( $project_checker = $statements_checker->getFileChecker()->project_checker; if (Checker\ClassChecker::checkFullyQualifiedClassLikeName( - $statements_checker, + $project_checker, $fq_class_name, $code_location, $suppressed_issues From bbf6d0494577e7e3f6fe4661e4fb209fbdef6032 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:11:03 -0500 Subject: [PATCH 03/17] Fix psalm.xml file --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index b099f1b..90c1719 100644 --- a/psalm.xml +++ b/psalm.xml @@ -28,7 +28,7 @@ - + From 05849ed00efa4aa43f01821c198559d7ab9c7cef Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:30:13 -0500 Subject: [PATCH 04/17] Extract response into multiple classes --- src/Message/AbstractResponse.php | 134 ++++++++ src/Message/ExtendedResponse.php | 532 +++++++++++++++++++++++++++++ src/Message/Response.php | 566 +------------------------------ 3 files changed, 676 insertions(+), 556 deletions(-) create mode 100644 src/Message/AbstractResponse.php create mode 100644 src/Message/ExtendedResponse.php diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php new file mode 100644 index 0000000..6ead990 --- /dev/null +++ b/src/Message/AbstractResponse.php @@ -0,0 +1,134 @@ +transaction = null; + } + + /** + * Returns true if the request was successful, false otherwise + * + * @return bool + */ + public function isSuccessful() + { + return substr($this->getCode() ?: '', 0, 1) === '2'; + } + + /** + * Get the ID from the HTTP request + * + * @return string|null + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * Set the ID from the HTTP request + * + * @param string|null $requestId + * @return static + */ + public function setRequestId($requestId) + { + $this->requestId = $requestId; + return $this; + } + + /** + * Get the HTTP response code + * + * @return string|null + */ + public function getCode() + { + return $this->code; + } + + /** + * Set the HTTP response code + * + * @param string $code + * @return static + */ + public function setCode($code) + { + $this->code = $code; + return $this; + } + + /** + * Overriding to provide more specific return type + * + * @return \Omnipay\BlueSnap\Message\AbstractRequest + */ + public function getRequest() + { + /** + * @var \Omnipay\BlueSnap\Message\AbstractRequest + */ + return parent::getRequest(); + } + + /** + * Get the error message from the response. Returns null if request was successful. + * + * Since this library works with both XML and JSON response data, this function checks for both types. + * + * @return string|null + * @psalm-suppress MixedPropertyFetch because we check the data typing before using. + */ + public function getMessage() + { + if (!$this->isSuccessful()) { + if ($this->data instanceof SimpleXMLElement && isset($this->data->message->description)) { + return (string) $this->data->message->description; + } + if (is_string($this->data)) { + return $this->data; + } // some error responses are plain text instead of XML + } + + return null; + } +} diff --git a/src/Message/ExtendedResponse.php b/src/Message/ExtendedResponse.php new file mode 100644 index 0000000..031f6fa --- /dev/null +++ b/src/Message/ExtendedResponse.php @@ -0,0 +1,532 @@ +transaction = null; + } + + /** + * Get the gateway's identifier for the customer + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getCustomerReference() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + if (isset($this->data->{'shopper-id'})) { + return (string) $this->data->{'shopper-id'}; + } + if (isset($this->data->{'shopper-info'}->{'shopper-id'})) { + return (string) $this->data->{'shopper-info'}->{'shopper-id'}; + } + if (isset($this->data->{'ordering-shopper'}->{'shopper-id'})) { + return (string) $this->data->{'ordering-shopper'}->{'shopper-id'}; + } + return null; + } + + /** + * Get the gateway's identifier for the transaction + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getTransactionReference() + { + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement && isset($this->invoice->{'invoice-id'})) { + return (string) $this->invoice->{'invoice-id'}; + } + if ($this->data instanceof SimpleXMLElement + && isset($this->data->{'charge-invoice-info'}->{'invoice-id'})) { + return (string) $this->data->{'charge-invoice-info'}->{'invoice-id'}; + } + + return null; + } + + /** + * Get the gateway's identifier for the subscription + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getSubscriptionReference() + { + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'subscription-id'})) { + return (string) $this->data->{'subscription-id'}; + } + return null; + } + + /** + * Get the monetary amount of a transaction or subscription + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getAmount() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement && isset($this->invoice->{'invoice-id'})) { + return (string) $this->invoice->{'financial-transactions'}->{'financial-transaction'}->amount; + } + // if an override charge is set, that's the current amount, not the catalog (original) one + if (isset($this->data->{'override-recurring-charge'}->amount)) { + return (string) $this->data->{'override-recurring-charge'}->amount; + } + if (isset($this->data->{'catalog-recurring-charge'}->amount)) { + return (string) $this->data->{'catalog-recurring-charge'}->amount; + } + if (isset($this->data->{'charge-invoice-info'}->{'invoice-amount'})) { + return (string) $this->data->{'charge-invoice-info'}->{'invoice-amount'}; + } + return null; + } + + /** + * Get the tax amount of a transaction or subscription + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getTax() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + // if an override charge is set, that's the current amount, not the catalog (original) one + if (isset($this->data->{'cart'}->tax)) { + return (string) $this->data->{'cart'}->tax; + } + return null; + } + + /** + * Get the currency of a transaction or subscription + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getCurrency() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement && isset($this->invoice->{'invoice-id'})) { + return (string) $this->invoice->{'financial-transactions'}->{'financial-transaction'}->currency; + } + // if an override charge is set, that's the current currency, not the catalog (original) one + if (isset($this->data->{'override-recurring-charge'}->currency)) { + return (string) $this->data->{'override-recurring-charge'}->currency; + } + if (isset($this->data->{'catalog-recurring-charge'}->currency)) { + return (string) $this->data->{'catalog-recurring-charge'}->currency; + } + if (isset($this->data->{'charge-invoice-info'}->{'invoice-currency'})) { + return (string) $this->data->{'charge-invoice-info'}->{'invoice-currency'}; + } + return null; + } + + /** + * Get an array of subscription charges from a subscription. + * will return the references of all charges made on that subscription. + * The empty array will be returned if there are no charges. + * + * @return array|null + * @psalm-suppress MixedPropertyFetch + * @psalm-suppress MixedAssignment + */ + public function getSubscriptionCharges() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + + $subscriptionCharges = array(); + if (isset($this->data->{'subscription-charges'})) { + foreach ($this->data->{'subscription-charges'}->children() as $charge) { + if (isset($charge->{'charge-invoice-info'})) { + $params = array( + 'date' => new DateTime( + (string) $charge->{'charge-invoice-info'}->{'date-created'}, + new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) + ), + 'transactionReference' => (string) $charge->{'charge-invoice-info'}->{'invoice-id'}, + 'amount' => (string) $charge->{'charge-invoice-info'}->{'invoice-amount'}, + 'currency' => (string) $charge->{'charge-invoice-info'}->{'invoice-currency'}, + 'customerReference' => (string) $this->getCustomerReference(), + 'subscriptionReference' => (string) $this->getSubscriptionReference() + ); + $subscriptionCharges[] = new SubscriptionCharge($params); + } + } + } + return !empty($subscriptionCharges) ? $subscriptionCharges : null; + } + + /** + * @return array|null + * @psalm-suppress MixedPropertyFetch + * @psalm-suppress MixedAssignment + */ + public function getSubscriptions() + { + // data can be SimpleXMLElement or JSON object + if (!isset($this->data) && !isset($this->data['data'])) { + return null; + } + + $subscriptions = array(); + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'subscriptions'})) { + foreach ($this->data->{'subscriptions'}->children() as $sub) { + $subscriptions[] = new Subscription(array( + 'subscriptionReference' => (string) $sub->{'subscription-id'}, + 'currency' => (string) $sub->{'catalog-recurring-charge'}->currency, + 'amount' => (string) $sub->{'catalog-recurring-charge'}->amount, + 'status' => (string) $sub->{'status'} + )); + } + return $subscriptions; + } + } + + /** + * Function to get a subscription status. + * + * Note that chargeback and refund statuses are not store here. To see if a transaction contains a refund or a + * chargeback refer to the following: + * + * @see Response::getChargebacks() or + * @see Response::getRefunds() + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getStatus() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + // Check if we have invoice and invoice status + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement && isset($this->invoice->{'invoice-id'})) { + return (string)$this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'status'}; + } + // check if status element is set and return + if (isset($this->data->{'status'})) { + return (string) $this->data->{'status'}; + } + return null; + } + + /** + * Function to get a plan reference. + * + * @return string|null + * @psalm-suppress MixedPropertyFetch + */ + public function getPlanReference() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + // Check if we have invoice and invoice plan reference (Bluesnap contract) + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement && isset($this->invoice->{'invoice-id'})) { + return (string) $this->invoice->{'financial-transactions'} + ->{'financial-transaction'} + ->{'skus'} + ->{'sku'} + ->{'sku-id'}; + } + // check if underlying-sku-id element is set and return + if (isset($this->data->{'underlying-sku-id'})) { + return (string) $this->data->{'underlying-sku-id'}; + } + return null; + } + + /** + * Get date the transaction or charge was created. + * NOTE: BlueSnap only returns dates, not times. + * The DateTime returned will be in the Etc/GMT+8 time zone. + * + * @return DateTime|null + * @psalm-suppress MixedPropertyFetch + */ + public function getDateCreated() + { + if (!$this->data instanceof SimpleXMLElement) { + return null; + } + + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement && isset($this->invoice->{'invoice-id'})) { + return new DateTime( + $this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'date-created'}, + new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) + ); + } + + $subscriptionCharges = $this->getSubscriptionCharges(); + if (!empty($subscriptionCharges)) { + return $subscriptionCharges[0]->getDate(); + } + + if (isset($this->data->{'charge-invoice-info'}->{'date-created'})) { + return new DateTime( + $this->data->{'charge-invoice-info'}->{'date-created'}, + new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) + ); + } + return null; + } + + /** + * Get the date of the next charge for a subscription + * NOTE: BlueSnap only returns dates, not times. + * The DateTime returned will be in the Etc/GMT+8 time zone. + * + * @return DateTime|null + * @psalm-suppress MixedPropertyFetch + */ + public function getNextChargeDate() + { + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'next-charge-date'})) { + return new DateTime( + $this->data->{'next-charge-date'}, + new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) + ); + } + return null; + } + + /** + * Get the decrypted parameters from the return url after a HostedCheckoutDecryptReturnUrlRequest + * Returns an array of paramName => paramValue + * + * @return array|null + * @psalm-suppress MixedPropertyFetch + */ + public function getDecryptedParameters() + { + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'decrypted-token'})) { + parse_str((string) $this->data->{'decrypted-token'}, $result); + return $result ?: null; + } + return null; + } + + /** + * Gets the credit card from a fetch transaction or subscription request + * + * @return null|CreditCard + */ + public function getCard() + { + $cardParams = array(); + + $cardXml = null; + $this->invoice = $this->getInvoice(); + if ($this->invoice instanceof SimpleXMLElement + && isset($this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'credit-card'}) + ) { + /** + * @var SimpleXMLElement + */ + $cardXml = $this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'credit-card'}; + } elseif ($this->data instanceof SimpleXMLElement && isset($this->data->{'credit-card'})) { + /** + * @var SimpleXMLElement + */ + $cardXml = $this->data->{'credit-card'}; + } + + if ($cardXml) { + if (isset($cardXml->{'card-type'})) { + $cardParams['brand'] = strtolower((string) $cardXml->{'card-type'}); + } + if (isset($cardXml->{'card-last-four-digits'})) { + $cardParams['number'] = (string) $cardXml->{'card-last-four-digits'}; + } + if (isset($cardXml->{'expiration-month'})) { + $cardParams['expiryMonth'] = (string) $cardXml->{'expiration-month'}; + } + if (isset($cardXml->{'expiration-year'})) { + $cardParams['expiryYear'] = (string) $cardXml->{'expiration-year'}; + } + } + + if ($this->invoice instanceof SimpleXMLElement + && isset($this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'invoice-contact-info'}) + ) { + /** + * @var SimpleXMLElement + */ + $contactXml = $this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'invoice-contact-info'}; + if (isset($contactXml->{'first-name'})) { + $cardParams['firstName'] = (string) $contactXml->{'first-name'}; + } + if (isset($contactXml->{'last-name'})) { + $cardParams['lastName'] = (string) $contactXml->{'last-name'}; + } + if (isset($contactXml->email)) { + $cardParams['email'] = (string) $contactXml->email; + } + if (isset($contactXml->state)) { + $cardParams['state'] = (string) $contactXml->state; + } + if (isset($contactXml->country)) { + $cardParams['country'] = (string) $contactXml->country; + } + if (isset($contactXml->zip)) { + $cardParams['postcode'] = (string) $contactXml->zip; + } + } + + if (!empty($cardParams)) { + return new CreditCard($cardParams); + } + return null; + } + + /** + * @return Transaction|null + */ + public function getTransaction() + { + if (!isset($this->transaction)) { + $this->invoice = $this->getInvoice(); + if ($this->invoice !== null) { + $params = [ + 'amount' => $this->getAmount(), + 'currency' => $this->getCurrency(), + 'customerReference' => $this->getCustomerReference(), + 'date' => $this->getDateCreated(), + 'status' => $this->getStatus(), // Note chargebacks + 'transactionReference' => $this->getTransactionReference(), + ]; + $this->transaction = new Transaction($params); + } + } + + return $this->transaction; + } + + /** + * Get the value of a custom parameter by name + * + * @param string $name + * @return string|null + */ + public function getCustomParameter($name) + { + if (!$this->data instanceof SimpleXMLElement + || !$this->data->cart instanceof SimpleXMLElement + || !isset($this->data->cart->{'cart-item'})) { + return null; + } + + /** + * @var SimpleXMLElement + */ + $parameters = $this->data->cart->{'cart-item'}->{'sku-parameter'}; + /** + * @var SimpleXMLElement + */ + foreach ($parameters as $parameter) { + if ($name === (string) $parameter->{'param-name'}) { + return (string) $parameter->{'param-value'}; + } + } + return null; + } + + /** + * Returns the invoice element corresponding to the requested transaction + * + * When you fetch an order, it may contain multiple invoices (for example, + * one for each subscription charge), so this function selects the correct + * one. + * + * @return SimpleXMLElement|null + */ + protected function getInvoice() + { + if ($this->invoice) { + return $this->invoice; + } + + $this->invoice = null; + // find the invoice that was reqeusted + $request = $this->getRequest(); + $transactionReference = $request->getTransactionReference(); + + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'post-sale-info'}->invoices)) { + /** + * @var SimpleXMLElement + */ + $invoices = $this->data->{'post-sale-info'}->invoices; + /** + * @var SimpleXMLElement + */ + foreach ($invoices->children() as $invoice) { + if (strval($invoice->{'invoice-id'}) === $transactionReference) { + $this->invoice = $invoice; + break; + } + } + } + return $this->invoice; + } +} diff --git a/src/Message/Response.php b/src/Message/Response.php index 4c21806..3b55efa 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -2,394 +2,29 @@ namespace Omnipay\BlueSnap\Message; -use Omnipay\Common\Message\AbstractResponse; use DateTime; use DateTimeZone; +use Exception; use Omnipay\BlueSnap\Constants; -use Omnipay\BlueSnap\Transaction; use Omnipay\BlueSnap\Subscription; -use Omnipay\BlueSnap\SubscriptionCharge; -use SimpleXMLElement; -use Omnipay\BlueSnap\CreditCard; +use Omnipay\BlueSnap\Transaction; /** - * BlueSnap response object. See Request files for usage. + * BlueSnap response object for the (non-extended) Payments API. See Request files or developer docs for usage. + * + * @link https://developers.bluesnap.com/v8976-JSON/docs */ class Response extends AbstractResponse { /** - * HTTP request id - * - * @var string|null - */ - protected $requestId; - - /** - * HTTP response code - * - * @var string|null - */ - protected $code; - - /** - * @var string|SimpleXMLElement|array - */ - protected $data; - - /** - * @var SimpleXMLElement|null - */ - protected $invoice; - - /** - * Returns true if the request was successful, false otherwise - * - * @return bool - */ - public function isSuccessful() - { - return substr($this->getCode() ?: '', 0, 1) === '2'; - } - - /** - * Get the ID from the HTTP request - * - * @return string|null - */ - public function getRequestId() - { - return $this->requestId; - } - - /** - * Set the ID from the HTTP request - * - * @param string|null $requestId - * @return static - */ - public function setRequestId($requestId) - { - $this->requestId = $requestId; - return $this; - } - - /** - * Get the HTTP response code - * - * @return string|null - */ - public function getCode() - { - return $this->code; - } - - /** - * Set the HTTP response code - * - * @param string $code - * @return static - */ - public function setCode($code) - { - $this->code = $code; - return $this; - } - - /** - * Get the error message from the response. Returns null if request was successful. - * - * @return string|null - * @psalm-suppress MixedPropertyFetch because we check the data typing before using. - */ - public function getMessage() - { - if (!$this->isSuccessful()) { - if ($this->data instanceof SimpleXMLElement && isset($this->data->message->description)) { - return (string) $this->data->message->description; - } - if (is_string($this->data)) { - return $this->data; - } // some error responses are plain text instead of XML - } - - return null; - } - - /** - * Get the gateway's identifier for the customer - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getCustomerReference() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - if (isset($this->data->{'shopper-id'})) { - return (string) $this->data->{'shopper-id'}; - } - if (isset($this->data->{'shopper-info'}->{'shopper-id'})) { - return (string) $this->data->{'shopper-info'}->{'shopper-id'}; - } - if (isset($this->data->{'ordering-shopper'}->{'shopper-id'})) { - return (string) $this->data->{'ordering-shopper'}->{'shopper-id'}; - } - return null; - } - - /** - * Get the gateway's identifier for the transaction - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getTransactionReference() - { - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement && isset($invoice->{'invoice-id'})) { - return (string) $invoice->{'invoice-id'}; - } - if ($this->data instanceof SimpleXMLElement - && isset($this->data->{'charge-invoice-info'}->{'invoice-id'})) { - return (string) $this->data->{'charge-invoice-info'}->{'invoice-id'}; - } - - return null; - } - - /** - * Get the gateway's identifier for the subscription - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getSubscriptionReference() - { - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'subscription-id'})) { - return (string) $this->data->{'subscription-id'}; - } - return null; - } - - /** - * Get the monetary amount of a transaction or subscription - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getAmount() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement && isset($invoice->{'invoice-id'})) { - return (string) $invoice->{'financial-transactions'}->{'financial-transaction'}->amount; - } - // if an override charge is set, that's the current amount, not the catalog (original) one - if (isset($this->data->{'override-recurring-charge'}->amount)) { - return (string) $this->data->{'override-recurring-charge'}->amount; - } - if (isset($this->data->{'catalog-recurring-charge'}->amount)) { - return (string) $this->data->{'catalog-recurring-charge'}->amount; - } - if (isset($this->data->{'charge-invoice-info'}->{'invoice-amount'})) { - return (string) $this->data->{'charge-invoice-info'}->{'invoice-amount'}; - } - return null; - } - - /** - * Get the tax amount of a transaction or subscription - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getTax() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - // if an override charge is set, that's the current amount, not the catalog (original) one - if (isset($this->data->{'cart'}->tax)) { - return (string) $this->data->{'cart'}->tax; - } - return null; - } - /** - * Get the currency of a transaction or subscription - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getCurrency() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement && isset($invoice->{'invoice-id'})) { - return (string) $invoice->{'financial-transactions'}->{'financial-transaction'}->currency; - } - // if an override charge is set, that's the current currency, not the catalog (original) one - if (isset($this->data->{'override-recurring-charge'}->currency)) { - return (string) $this->data->{'override-recurring-charge'}->currency; - } - if (isset($this->data->{'catalog-recurring-charge'}->currency)) { - return (string) $this->data->{'catalog-recurring-charge'}->currency; - } - if (isset($this->data->{'charge-invoice-info'}->{'invoice-currency'})) { - return (string) $this->data->{'charge-invoice-info'}->{'invoice-currency'}; - } - return null; - } - - /** - * Get an array of subscription charges from a subscription. - * will return the references of all charges made on that subscription. - * The empty array will be returned if there are no charges. - * - * @return array|null - * @psalm-suppress MixedPropertyFetch - * @psalm-suppress MixedAssignment - */ - public function getSubscriptionCharges() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - - $subscriptionCharges = array(); - if (isset($this->data->{'subscription-charges'})) { - foreach ($this->data->{'subscription-charges'}->children() as $charge) { - if (isset($charge->{'charge-invoice-info'})) { - $params = array( - 'date' => new DateTime( - (string) $charge->{'charge-invoice-info'}->{'date-created'}, - new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) - ), - 'transactionReference' => (string) $charge->{'charge-invoice-info'}->{'invoice-id'}, - 'amount' => (string) $charge->{'charge-invoice-info'}->{'invoice-amount'}, - 'currency' => (string) $charge->{'charge-invoice-info'}->{'invoice-currency'}, - 'customerReference' => (string) $this->getCustomerReference(), - 'subscriptionReference' => (string) $this->getSubscriptionReference() - ); - $subscriptionCharges[] = new SubscriptionCharge($params); - } - } - } - return !empty($subscriptionCharges) ? $subscriptionCharges : null; - } - - - /** - * Function to get a subscription status. - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getStatus() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - // Check if we have invoice and invoice status - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement && isset($invoice->{'invoice-id'})) { - return (string)$invoice->{'financial-transactions'}->{'financial-transaction'}->{'status'}; - } - // check if status element is set and return - if (isset($this->data->{'status'})) { - return (string) $this->data->{'status'}; - } - return null; - } - - /** - * Function to get a plan reference. - * - * @return string|null - * @psalm-suppress MixedPropertyFetch - */ - public function getPlanReference() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - // Check if we have invoice and invoice plan reference (Bluesnap contract) - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement && isset($invoice->{'invoice-id'})) { - return (string) $invoice->{'financial-transactions'} - ->{'financial-transaction'} - ->{'skus'} - ->{'sku'} - ->{'sku-id'}; - } - // check if underlying-sku-id element is set and return - if (isset($this->data->{'underlying-sku-id'})) { - return (string) $this->data->{'underlying-sku-id'}; - } - return null; - } - - /** - * Get date the transaction or charge was created. - * NOTE: BlueSnap only returns dates, not times. - * The DateTime returned will be in the Etc/GMT+8 time zone. + * Retrieves multiple transactions data from the response. * - * @return DateTime|null - * @psalm-suppress MixedPropertyFetch - */ - public function getDateCreated() - { - if (!$this->data instanceof SimpleXMLElement) { - return null; - } - - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement && isset($invoice->{'invoice-id'})) { - return new DateTime( - $invoice->{'financial-transactions'}->{'financial-transaction'}->{'date-created'}, - new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) - ); - } - - $subscriptionCharges = $this->getSubscriptionCharges(); - if (!empty($subscriptionCharges)) { - return $subscriptionCharges[0]->getDate(); - } - - if (isset($this->data->{'charge-invoice-info'}->{'date-created'})) { - return new DateTime( - $this->data->{'charge-invoice-info'}->{'date-created'}, - new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) - ); - } - return null; - } - - /** - * Get the date of the next charge for a subscription - * NOTE: BlueSnap only returns dates, not times. - * The DateTime returned will be in the Etc/GMT+8 time zone. + * This data can only be retrieved if the request was issued via @link FetchTransactionsRequest which uses the + * Reporting API. If the transaction data was retrieved via @link ExtendedFetchTransactionRequest this method will + * return null. To retrieve transaction data from the extended request see @link ExtendedResponse::getTransaction() * - * @return DateTime|null - * @psalm-suppress MixedPropertyFetch - */ - public function getNextChargeDate() - { - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'next-charge-date'})) { - return new DateTime( - $this->data->{'next-charge-date'}, - new DateTimeZone(Constants::BLUESNAP_TIME_ZONE) - ); - } - return null; - } - - /** * @return array|null + * @throws Exception */ public function getTransactions() { @@ -434,18 +69,6 @@ public function getSubscriptions() } $subscriptions = array(); - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'subscriptions'})) { - foreach ($this->data->{'subscriptions'}->children() as $sub) { - $subscriptions[] = new Subscription(array( - 'subscriptionReference' => (string) $sub->{'subscription-id'}, - 'currency' => (string) $sub->{'catalog-recurring-charge'}->currency, - 'amount' => (string) $sub->{'catalog-recurring-charge'}->amount, - 'status' => (string) $sub->{'status'} - )); - } - return $subscriptions; - } - if (is_array($this->data)) { /** @var array */ foreach ($this->data['data'] as $row) { @@ -460,173 +83,4 @@ public function getSubscriptions() } return $subscriptions; } - - /** - * Get the decrypted parameters from the return url after a HostedCheckoutDecryptReturnUrlRequest - * Returns an array of paramName => paramValue - * - * @return array|null - * @psalm-suppress MixedPropertyFetch - */ - public function getDecryptedParameters() - { - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'decrypted-token'})) { - parse_str((string) $this->data->{'decrypted-token'}, $result); - return $result ?: null; - } - return null; - } - - /** - * Gets the credit card from a fetch transaction or subscription request - * - * @return null|CreditCard - */ - public function getCard() - { - $cardParams = array(); - - $cardXml = null; - $invoice = $this->getInvoice(); - if ($invoice instanceof SimpleXMLElement - && isset($invoice->{'financial-transactions'}->{'financial-transaction'}->{'credit-card'}) - ) { - /** - * @var SimpleXMLElement - */ - $cardXml = $invoice->{'financial-transactions'}->{'financial-transaction'}->{'credit-card'}; - } elseif ($this->data instanceof SimpleXMLElement && isset($this->data->{'credit-card'})) { - /** - * @var SimpleXMLElement - */ - $cardXml = $this->data->{'credit-card'}; - } - - if ($cardXml) { - if (isset($cardXml->{'card-type'})) { - $cardParams['brand'] = strtolower((string) $cardXml->{'card-type'}); - } - if (isset($cardXml->{'card-last-four-digits'})) { - $cardParams['number'] = (string) $cardXml->{'card-last-four-digits'}; - } - if (isset($cardXml->{'expiration-month'})) { - $cardParams['expiryMonth'] = (string) $cardXml->{'expiration-month'}; - } - if (isset($cardXml->{'expiration-year'})) { - $cardParams['expiryYear'] = (string) $cardXml->{'expiration-year'}; - } - } - - if ($invoice instanceof SimpleXMLElement - && isset($invoice->{'financial-transactions'}->{'financial-transaction'}->{'invoice-contact-info'}) - ) { - /** - * @var SimpleXMLElement - */ - $contactXml = $invoice->{'financial-transactions'}->{'financial-transaction'}->{'invoice-contact-info'}; - if (isset($contactXml->{'first-name'})) { - $cardParams['firstName'] = (string) $contactXml->{'first-name'}; - } - if (isset($contactXml->{'last-name'})) { - $cardParams['lastName'] = (string) $contactXml->{'last-name'}; - } - if (isset($contactXml->email)) { - $cardParams['email'] = (string) $contactXml->email; - } - if (isset($contactXml->state)) { - $cardParams['state'] = (string) $contactXml->state; - } - if (isset($contactXml->country)) { - $cardParams['country'] = (string) $contactXml->country; - } - if (isset($contactXml->zip)) { - $cardParams['postcode'] = (string) $contactXml->zip; - } - } - - if (!empty($cardParams)) { - return new CreditCard($cardParams); - } - return null; - } - - /** - * Get the value of a custom parameter by name - * - * @param string $name - * @return string|null - */ - public function getCustomParameter($name) - { - if (!$this->data instanceof SimpleXMLElement - || !$this->data->cart instanceof SimpleXMLElement - || !isset($this->data->cart->{'cart-item'})) { - return null; - } - - /** - * @var SimpleXMLElement - */ - $parameters = $this->data->cart->{'cart-item'}->{'sku-parameter'}; - /** - * @var SimpleXMLElement - */ - foreach ($parameters as $parameter) { - if ($name === (string) $parameter->{'param-name'}) { - return (string) $parameter->{'param-value'}; - } - } - return null; - } - - /** - * Returns the invoice element corresponding to the requested transaction - * - * When you fetch an order, it may contain multiple invoices (for example, - * one for each subscription charge), so this function selects the correct - * one. - * - * @return SimpleXMLElement|null - */ - protected function getInvoice() - { - if ($this->invoice) { - return $this->invoice; - } - - $this->invoice = null; - // find the invoice that was reqeusted - $request = $this->getRequest(); - $transactionReference = $request->getTransactionReference(); - - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'post-sale-info'}->invoices)) { - /** - * @var SimpleXMLElement - */ - $invoices = $this->data->{'post-sale-info'}->invoices; - /** - * @var SimpleXMLElement - */ - foreach ($invoices->children() as $invoice) { - if (strval($invoice->{'invoice-id'}) === $transactionReference) { - $this->invoice = $invoice; - break; - } - } - } - return $this->invoice; - } - - /** - * Overriding to provide more specific return type - * - * @return \Omnipay\BlueSnap\Message\AbstractRequest - */ - public function getRequest() - { - /** - * @var \Omnipay\BlueSnap\Message\AbstractRequest - */ - return parent::getRequest(); - } } From deea412ca390dfdf6bc5ebfb8825646a414ce09e Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:34:45 -0500 Subject: [PATCH 05/17] Override response class in ExtendedAbstractRequest to match new extended response class --- src/Message/ExtendedAbstractRequest.php | 10 ++++++++-- tests/EventEmitterTest.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Message/ExtendedAbstractRequest.php b/src/Message/ExtendedAbstractRequest.php index e1ffd2e..bea877c 100644 --- a/src/Message/ExtendedAbstractRequest.php +++ b/src/Message/ExtendedAbstractRequest.php @@ -11,6 +11,12 @@ */ abstract class ExtendedAbstractRequest extends AbstractRequest { + /** + * @var string + */ + protected static $RESPONSE_CLASS = '\Omnipay\BlueSnap\Message\ExtendedResponse'; + + /** * Gets the gateway's identifier for the store (BlueSnap calls this the store ID) * @@ -84,12 +90,12 @@ public function setStoreParameters($parameters) /** * Overriding to provide a more precise return type * - * @return Response + * @return ExtendedResponse */ public function send() { /** - * @var Response + * @var ExtendedResponse */ return parent::send(); } diff --git a/tests/EventEmitterTest.php b/tests/EventEmitterTest.php index 6fa38c0..7dbf385 100644 --- a/tests/EventEmitterTest.php +++ b/tests/EventEmitterTest.php @@ -78,7 +78,7 @@ function (RequestEvent $event) use ($class) { function (ResponseEvent $event) use ($class) { /** @var ResponseInterface $response */ $response = $event['response']; - $class->assertInstanceOf('\Omnipay\BlueSnap\Message\Response', $response); + $class->assertInstanceOf('\Omnipay\BlueSnap\Message\ExtendedResponse', $response); } ); From a7c06f6a56fc1f724e140167630e37c83f7dda9b Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:35:30 -0500 Subject: [PATCH 06/17] Have HostedCheckoutPurchaseResponse extend new AbstractResponse class --- src/Message/HostedCheckoutPurchaseResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/HostedCheckoutPurchaseResponse.php b/src/Message/HostedCheckoutPurchaseResponse.php index 251660c..0133954 100644 --- a/src/Message/HostedCheckoutPurchaseResponse.php +++ b/src/Message/HostedCheckoutPurchaseResponse.php @@ -2,13 +2,13 @@ namespace Omnipay\BlueSnap\Message; -use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\BlueSnap\Constants; +use Omnipay\Common\Message\RedirectResponseInterface; /** * Response object for the HostedCheckoutPurchaseRequest. See that file for details. */ -class HostedCheckoutPurchaseResponse extends Response implements RedirectResponseInterface +class HostedCheckoutPurchaseResponse extends AbstractResponse implements RedirectResponseInterface { /** * Returns true if the response is a redirect, false otherwise. From 4228f852f82fb70c7c2a98fe947de44b18b0bb57 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 10:47:12 -0500 Subject: [PATCH 07/17] Move getDecryptedParameters to Response since it's part of the non-extended API --- src/Message/ExtendedResponse.php | 17 ----------------- .../HostedCheckoutDecryptReturnUrlRequest.php | 5 ++--- src/Message/Response.php | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Message/ExtendedResponse.php b/src/Message/ExtendedResponse.php index 031f6fa..2535dec 100644 --- a/src/Message/ExtendedResponse.php +++ b/src/Message/ExtendedResponse.php @@ -4,7 +4,6 @@ namespace Omnipay\BlueSnap\Message; -use Closure; use DateTime; use DateTimeZone; use Omnipay\BlueSnap\Constants; @@ -351,22 +350,6 @@ public function getNextChargeDate() return null; } - /** - * Get the decrypted parameters from the return url after a HostedCheckoutDecryptReturnUrlRequest - * Returns an array of paramName => paramValue - * - * @return array|null - * @psalm-suppress MixedPropertyFetch - */ - public function getDecryptedParameters() - { - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'decrypted-token'})) { - parse_str((string) $this->data->{'decrypted-token'}, $result); - return $result ?: null; - } - return null; - } - /** * Gets the credit card from a fetch transaction or subscription request * diff --git a/src/Message/HostedCheckoutDecryptReturnUrlRequest.php b/src/Message/HostedCheckoutDecryptReturnUrlRequest.php index 2cc1649..6b8aba0 100644 --- a/src/Message/HostedCheckoutDecryptReturnUrlRequest.php +++ b/src/Message/HostedCheckoutDecryptReturnUrlRequest.php @@ -2,9 +2,8 @@ namespace Omnipay\BlueSnap\Message; -use Omnipay\Common\Exception\InvalidRequestException; -use SimpleXMLElement; use Omnipay\BlueSnap\Constants; +use SimpleXMLElement; /** * Decrypts an encrypted return URL. @@ -51,7 +50,7 @@ * } * */ -class HostedCheckoutDecryptReturnUrlRequest extends ExtendedAbstractRequest +class HostedCheckoutDecryptReturnUrlRequest extends AbstractRequest { /** * @return SimpleXMLElement diff --git a/src/Message/Response.php b/src/Message/Response.php index 3b55efa..5846272 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -8,6 +8,7 @@ use Omnipay\BlueSnap\Constants; use Omnipay\BlueSnap\Subscription; use Omnipay\BlueSnap\Transaction; +use SimpleXMLElement; /** * BlueSnap response object for the (non-extended) Payments API. See Request files or developer docs for usage. @@ -83,4 +84,20 @@ public function getSubscriptions() } return $subscriptions; } + + /** + * Get the decrypted parameters from the return url after a HostedCheckoutDecryptReturnUrlRequest + * Returns an array of paramName => paramValue + * + * @return array|null + * @psalm-suppress MixedPropertyFetch + */ + public function getDecryptedParameters() + { + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'decrypted-token'})) { + parse_str((string) $this->data->{'decrypted-token'}, $result); + return $result ?: null; + } + return null; + } } From 7d0b34e3ba6ab9e20790c294f6117d34f5574172 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 11:32:01 -0500 Subject: [PATCH 08/17] Add abstract keyword --- src/Message/AbstractResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index 6ead990..b25ba1b 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -7,7 +7,7 @@ use Omnipay\Common\Message\RequestInterface; use SimpleXMLElement; -class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse +abstract class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse { /** * HTTP request id From 816d438aa962ffa571677a1f208de4b0be9ed0c9 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 11:40:13 -0500 Subject: [PATCH 09/17] Extract into ReportingAbstractRequest class --- src/Message/FetchTransactionsRequest.php | 48 +----------------- src/Message/ReportingAbstractRequest.php | 64 ++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 src/Message/ReportingAbstractRequest.php diff --git a/src/Message/FetchTransactionsRequest.php b/src/Message/FetchTransactionsRequest.php index 660d5e9..defa2a0 100644 --- a/src/Message/FetchTransactionsRequest.php +++ b/src/Message/FetchTransactionsRequest.php @@ -2,7 +2,6 @@ namespace Omnipay\BlueSnap\Message; -use Omnipay\BlueSnap\Constants; use Omnipay\Common\Exception\InvalidRequestException; /** @@ -47,52 +46,7 @@ * } * */ -class FetchTransactionsRequest extends AbstractRequest +class FetchTransactionsRequest extends ReportingAbstractRequest { const REPORT_NAME = 'TransactionDetail'; - - /** - * @return null - */ - public function getData() - { - $this->validate('startTime'); - $this->validate('endTime'); - - if ($this->getStartTime() > $this->getEndTime()) { - throw new InvalidRequestException('startTime cannot be greater than endTime'); - } - - return null; - } - - /** - * Return the API endpoint. - * - * @return string - */ - public function getEndpoint() - { - $startTime = $this->getStartTime(); - $endTime = $this->getEndTime(); - $endpoint = parent::getEndpoint() . '/report/' . (string) static::REPORT_NAME; - - // this should always be true - if ($startTime && $endTime) { - $endpoint .= '?period=CUSTOM' - . '&from_date=' . urlencode((string) $startTime->format('m/d/Y')) - . '&to_date=' . urlencode((string) $endTime->format('m/d/Y')); - } - return $endpoint; - } - - /** - * Returns the HTTP method to be used for this request - * - * @return string - */ - public function getHttpMethod() - { - return Constants::HTTP_METHOD_GET; - } } diff --git a/src/Message/ReportingAbstractRequest.php b/src/Message/ReportingAbstractRequest.php new file mode 100644 index 0000000..94300fa --- /dev/null +++ b/src/Message/ReportingAbstractRequest.php @@ -0,0 +1,64 @@ +validate('startTime'); + $this->validate('endTime'); + + if ($this->getStartTime() > $this->getEndTime()) { + throw new InvalidRequestException('startTime cannot be greater than endTime'); + } + + return null; + } + + /** + * Return the API endpoint. + * + * @return string + */ + public function getEndpoint() + { + $startTime = $this->getStartTime(); + $endTime = $this->getEndTime(); + $endpoint = parent::getEndpoint() . '/report/' . static::REPORT_NAME; + + // this should always be true + if ($startTime && $endTime) { + $endpoint .= '?period=CUSTOM' + . '&from_date=' . urlencode((string) $startTime->format('m/d/Y')) + . '&to_date=' . urlencode((string) $endTime->format('m/d/Y')); + } + return $endpoint; + } +} From c0995048c0b22d11a4160554639e618046251e5e Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Mon, 11 Jan 2021 11:47:54 -0500 Subject: [PATCH 10/17] Rename reporting requests --- src/ExtendedGateway.php | 7 ++--- src/Gateway.php | 27 ++++++++++--------- .../ExtendedFetchSubscriptionsRequest.php | 4 +-- src/Message/ReportingAbstractRequest.php | 7 ++++- ...tingFetchCanceledSubscriptionsRequest.php} | 12 +++++++-- ...=> ReportingFetchSubscriptionsRequest.php} | 9 +++++-- ... => ReportingFetchTransactionsRequest.php} | 10 ++++++- src/Message/Response.php | 2 +- tests/ExtendedGatewayTest.php | 2 +- tests/GatewayTest.php | 6 ++--- .../FetchCanceledSubscriptionsRequestTest.php | 4 +-- .../Message/FetchSubscriptionsRequestTest.php | 4 +-- .../Message/FetchTransactionsRequestTest.php | 4 +-- 13 files changed, 64 insertions(+), 34 deletions(-) rename src/Message/{FetchCanceledSubscriptionsRequest.php => ReportingFetchCanceledSubscriptionsRequest.php} (86%) rename src/Message/{FetchSubscriptionsRequest.php => ReportingFetchSubscriptionsRequest.php} (87%) rename src/Message/{FetchTransactionsRequest.php => ReportingFetchTransactionsRequest.php} (91%) diff --git a/src/ExtendedGateway.php b/src/ExtendedGateway.php index 25006ee..a7e35ba 100644 --- a/src/ExtendedGateway.php +++ b/src/ExtendedGateway.php @@ -72,18 +72,19 @@ public function fetchSubscription(array $parameters = array()) * Fetch BlueSnap subscription objects by customer or in a time range. * * See Message\ExtendedFetchSubscriptionsRequest for more details on fetching - * by customer. See Message\FetchSubscriptionsRequest for more details on + * by customer. See Message\ReportingFetchSubscriptionsRequest for more details on * fetching by time range. The correct request will be made depending on the * parameters passed. * * @param array $parameters - * @return \Omnipay\BlueSnap\Message\FetchSubscriptionsRequest + * + * @return \Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest */ public function fetchSubscriptions(array $parameters = array()) { if (isset($parameters['customerReference'])) { /** - * @var \Omnipay\BlueSnap\Message\FetchSubscriptionsRequest + * @var \Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest */ return $this->createRequest( '\Omnipay\BlueSnap\Message\ExtendedFetchSubscriptionsRequest', diff --git a/src/Gateway.php b/src/Gateway.php index 407ba0e..b3c8890 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -81,49 +81,52 @@ public function setPassword($value) /** * Fetch all transactions in a time range. * - * See Message\FetchTransactionsRequest for more details. + * See Message\ReportingFetchTransactionsRequest for more details. * * @param array $parameters - * @return \Omnipay\BlueSnap\Message\FetchTransactionsRequest + * + * @return \Omnipay\BlueSnap\Message\ReportingFetchTransactionsRequest */ public function fetchTransactions(array $parameters = array()) { /** - * @var \Omnipay\BlueSnap\Message\FetchTransactionsRequest + * @var \Omnipay\BlueSnap\Message\ReportingFetchTransactionsRequest */ - return $this->createRequest('\Omnipay\BlueSnap\Message\FetchTransactionsRequest', $parameters); + return $this->createRequest('\Omnipay\BlueSnap\Message\ReportingFetchTransactionsRequest', $parameters); } /** * Fetch all active subscriptions in a time range. * - * See Message\FetchSubscriptionsRequest for more details. + * See Message\ReportingFetchSubscriptionsRequest for more details. * * @param array $parameters - * @return \Omnipay\BlueSnap\Message\FetchSubscriptionsRequest + * + * @return \Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest */ public function fetchSubscriptions(array $parameters = array()) { /** - * @var \Omnipay\BlueSnap\Message\FetchSubscriptionsRequest + * @var \Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest */ - return $this->createRequest('\Omnipay\BlueSnap\Message\FetchSubscriptionsRequest', $parameters); + return $this->createRequest('\Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest', $parameters); } /** * Fetch all canceled subscriptions in a time range. * - * See Message\FetchCanceledSubscriptionsRequest for more details. + * See Message\ReportingFetchCanceledSubscriptionsRequest for more details. * * @param array $parameters - * @return \Omnipay\BlueSnap\Message\FetchCanceledSubscriptionsRequest + * + * @return \Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest */ public function fetchCanceledSubscriptions(array $parameters = array()) { /** - * @var \Omnipay\BlueSnap\Message\FetchCanceledSubscriptionsRequest + * @var \Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest */ - return $this->createRequest('\Omnipay\BlueSnap\Message\FetchCanceledSubscriptionsRequest', $parameters); + return $this->createRequest('\Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest', $parameters); } /** diff --git a/src/Message/ExtendedFetchSubscriptionsRequest.php b/src/Message/ExtendedFetchSubscriptionsRequest.php index 9655c3d..67ba7a9 100644 --- a/src/Message/ExtendedFetchSubscriptionsRequest.php +++ b/src/Message/ExtendedFetchSubscriptionsRequest.php @@ -7,8 +7,8 @@ /** * Fetch subscriptions by customer reference. * - * If you want to fetch all subscriptions in a time range, see FetchSubscriptionsRequest. - * If you want to fetch all canceled subscriptions, see FetchCanceledSubscriptionsRequest. + * If you want to fetch all subscriptions in a time range, see ReportingFetchSubscriptionsRequest. + * If you want to fetch all canceled subscriptions, see ReportingFetchCanceledSubscriptionsRequest. * If you only want to fetch a single subscription, see ExtendedFetchSubscriptionRequest. * * Parameters: diff --git a/src/Message/ReportingAbstractRequest.php b/src/Message/ReportingAbstractRequest.php index 94300fa..476a922 100644 --- a/src/Message/ReportingAbstractRequest.php +++ b/src/Message/ReportingAbstractRequest.php @@ -16,6 +16,11 @@ */ abstract class ReportingAbstractRequest extends AbstractRequest { + /** + * @return string + */ + abstract public function getReportName(); + /** * Returns the HTTP method to be used for this request * @@ -51,7 +56,7 @@ public function getEndpoint() { $startTime = $this->getStartTime(); $endTime = $this->getEndTime(); - $endpoint = parent::getEndpoint() . '/report/' . static::REPORT_NAME; + $endpoint = parent::getEndpoint() . '/report/' . $this->getReportName(); // this should always be true if ($startTime && $endTime) { diff --git a/src/Message/FetchCanceledSubscriptionsRequest.php b/src/Message/ReportingFetchCanceledSubscriptionsRequest.php similarity index 86% rename from src/Message/FetchCanceledSubscriptionsRequest.php rename to src/Message/ReportingFetchCanceledSubscriptionsRequest.php index 3111f88..03409f5 100644 --- a/src/Message/FetchCanceledSubscriptionsRequest.php +++ b/src/Message/ReportingFetchCanceledSubscriptionsRequest.php @@ -5,7 +5,7 @@ /** * Fetch all canceled subscriptions in a time range. * - * If you want to fetch all active subscriptions, see FetchSubscriptionsRequest. + * If you want to fetch all active subscriptions, see ReportingFetchSubscriptionsRequest. * If you only want to fetch a single subscription, see ExtendedFetchSubscriptionRequest. * If you want to fetch all subscriptions by customer, see ExtendedFetchSubscriptionsRequest. * @@ -42,7 +42,15 @@ * } * */ -class FetchCanceledSubscriptionsRequest extends FetchSubscriptionsRequest +class ReportingFetchCanceledSubscriptionsRequest extends ReportingAbstractRequest { const REPORT_NAME = 'CanceledSubscriptions'; + + /** + * @return string + */ + public function getReportName() + { + return self::REPORT_NAME; + } } diff --git a/src/Message/FetchSubscriptionsRequest.php b/src/Message/ReportingFetchSubscriptionsRequest.php similarity index 87% rename from src/Message/FetchSubscriptionsRequest.php rename to src/Message/ReportingFetchSubscriptionsRequest.php index 5f6ac60..9fa18d7 100644 --- a/src/Message/FetchSubscriptionsRequest.php +++ b/src/Message/ReportingFetchSubscriptionsRequest.php @@ -5,7 +5,7 @@ /** * Fetch all subscriptions in a time range. * - * If you want to fetch all canceled subscriptions, see FetchCanceledSubscriptionsRequest. + * If you want to fetch all canceled subscriptions, see ReportingFetchCanceledSubscriptionsRequest. * If you only want to fetch a single subscription, see ExtendedFetchSubscriptionRequest. * If you want to fetch all subscriptions by customer, see ExtendedFetchSubscriptionsRequest. * @@ -42,7 +42,12 @@ * } * */ -class FetchSubscriptionsRequest extends FetchTransactionsRequest +class ReportingFetchSubscriptionsRequest extends ReportingAbstractRequest { const REPORT_NAME = 'ActiveSubscriptions'; + + public function getReportName() + { + return self::REPORT_NAME; + } } diff --git a/src/Message/FetchTransactionsRequest.php b/src/Message/ReportingFetchTransactionsRequest.php similarity index 91% rename from src/Message/FetchTransactionsRequest.php rename to src/Message/ReportingFetchTransactionsRequest.php index defa2a0..94e1249 100644 --- a/src/Message/FetchTransactionsRequest.php +++ b/src/Message/ReportingFetchTransactionsRequest.php @@ -46,7 +46,15 @@ * } * */ -class FetchTransactionsRequest extends ReportingAbstractRequest +class ReportingFetchTransactionsRequest extends ReportingAbstractRequest { const REPORT_NAME = 'TransactionDetail'; + + /** + * @return string + */ + public function getReportName() + { + return self::REPORT_NAME; + } } diff --git a/src/Message/Response.php b/src/Message/Response.php index 5846272..d9931d1 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -20,7 +20,7 @@ class Response extends AbstractResponse /** * Retrieves multiple transactions data from the response. * - * This data can only be retrieved if the request was issued via @link FetchTransactionsRequest which uses the + * This data can only be retrieved if the request was issued via @link ReportingFetchTransactionsRequest which uses the * Reporting API. If the transaction data was retrieved via @link ExtendedFetchTransactionRequest this method will * return null. To retrieve transaction data from the extended request see @link ExtendedResponse::getTransaction() * diff --git a/tests/ExtendedGatewayTest.php b/tests/ExtendedGatewayTest.php index 9340dee..3cf188c 100644 --- a/tests/ExtendedGatewayTest.php +++ b/tests/ExtendedGatewayTest.php @@ -215,7 +215,7 @@ public function testFetchSubscriptionsByTimeRange() 'endTime' => $endTime ) ); - $this->assertInstanceOf('Omnipay\BlueSnap\Message\FetchSubscriptionsRequest', $request); + $this->assertInstanceOf('Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest', $request); $this->assertSame($startTime, $request->getStartTime()); $this->assertSame($endTime, $request->getEndTime()); } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 143609d..0f2d2ae 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -97,7 +97,7 @@ public function testFetchTransactions() 'endTime' => $endTime ) ); - $this->assertInstanceOf('Omnipay\BlueSnap\Message\FetchTransactionsRequest', $request); + $this->assertInstanceOf('Omnipay\BlueSnap\Message\ReportingFetchTransactionsRequest', $request); $this->assertSame($startTime, $request->getStartTime()); $this->assertSame($endTime, $request->getEndTime()); } @@ -115,7 +115,7 @@ public function testFetchSubscriptions() 'endTime' => $endTime ) ); - $this->assertInstanceOf('Omnipay\BlueSnap\Message\FetchSubscriptionsRequest', $request); + $this->assertInstanceOf('Omnipay\BlueSnap\Message\ReportingFetchSubscriptionsRequest', $request); $this->assertSame($startTime, $request->getStartTime()); $this->assertSame($endTime, $request->getEndTime()); } @@ -133,7 +133,7 @@ public function testFetchCanceledSubscriptions() 'endTime' => $endTime ) ); - $this->assertInstanceOf('Omnipay\BlueSnap\Message\FetchCanceledSubscriptionsRequest', $request); + $this->assertInstanceOf('Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest', $request); $this->assertSame($startTime, $request->getStartTime()); $this->assertSame($endTime, $request->getEndTime()); } diff --git a/tests/Message/FetchCanceledSubscriptionsRequestTest.php b/tests/Message/FetchCanceledSubscriptionsRequestTest.php index 4443a30..1a80b09 100644 --- a/tests/Message/FetchCanceledSubscriptionsRequestTest.php +++ b/tests/Message/FetchCanceledSubscriptionsRequestTest.php @@ -15,7 +15,7 @@ class FetchCanceledSubscriptionsRequestTest extends OmnipayBlueSnapTestCase protected $faker; /** - * @var FetchCanceledSubscriptionsRequest + * @var ReportingFetchCanceledSubscriptionsRequest */ protected $request; @@ -45,7 +45,7 @@ public function setUp() $this->startTime = $temp; } - $this->request = new FetchCanceledSubscriptionsRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request = new ReportingFetchCanceledSubscriptionsRequest($this->getHttpClient(), $this->getHttpRequest()); } /** diff --git a/tests/Message/FetchSubscriptionsRequestTest.php b/tests/Message/FetchSubscriptionsRequestTest.php index 79c424b..4e05396 100644 --- a/tests/Message/FetchSubscriptionsRequestTest.php +++ b/tests/Message/FetchSubscriptionsRequestTest.php @@ -16,7 +16,7 @@ class FetchSubscriptionsRequestTest extends OmnipayBlueSnapTestCase protected $faker; /** - * @var FetchSubscriptionsRequest + * @var ReportingFetchSubscriptionsRequest */ protected $request; @@ -46,7 +46,7 @@ public function setUp() $this->startTime = $temp; } - $this->request = new FetchSubscriptionsRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request = new ReportingFetchSubscriptionsRequest($this->getHttpClient(), $this->getHttpRequest()); } /** diff --git a/tests/Message/FetchTransactionsRequestTest.php b/tests/Message/FetchTransactionsRequestTest.php index 031440b..58d881d 100644 --- a/tests/Message/FetchTransactionsRequestTest.php +++ b/tests/Message/FetchTransactionsRequestTest.php @@ -16,7 +16,7 @@ class FetchTransactionsRequestTest extends OmnipayBlueSnapTestCase protected $faker; /** - * @var FetchTransactionsRequest + * @var ReportingFetchTransactionsRequest */ protected $request; @@ -46,7 +46,7 @@ public function setUp() $this->startTime = $temp; } - $this->request = new FetchTransactionsRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request = new ReportingFetchTransactionsRequest($this->getHttpClient(), $this->getHttpRequest()); } /** From 6b323564c918009776ed0cdb4c5597b00c5a86a8 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Tue, 19 Jan 2021 10:06:05 -0500 Subject: [PATCH 11/17] Prefix remaining files with Reporting --- ...portingFetchCanceledSubscriptionsRequestTest.php} | 6 +++--- ...hp => ReportingFetchSubscriptionsRequestTest.php} | 6 +++--- ...php => ReportingFetchTransactionsRequestTest.php} | 12 +++++------- ...> ReportingFetchCanceledSubscriptionsFailure.txt} | 0 ...> ReportingFetchCanceledSubscriptionsSuccess.txt} | 0 ...re.txt => ReportingFetchSubscriptionsFailure.txt} | 0 ...ss.txt => ReportingFetchSubscriptionsSuccess.txt} | 0 ...ure.txt => ReportingFetchTransactionsFailure.txt} | 0 ...ess.txt => ReportingFetchTransactionsSuccess.txt} | 0 9 files changed, 11 insertions(+), 13 deletions(-) rename tests/Message/{FetchCanceledSubscriptionsRequestTest.php => ReportingFetchCanceledSubscriptionsRequestTest.php} (96%) rename tests/Message/{FetchSubscriptionsRequestTest.php => ReportingFetchSubscriptionsRequestTest.php} (95%) rename tests/Message/{FetchTransactionsRequestTest.php => ReportingFetchTransactionsRequestTest.php} (96%) rename tests/Mock/{FetchCanceledSubscriptionsFailure.txt => ReportingFetchCanceledSubscriptionsFailure.txt} (100%) rename tests/Mock/{FetchCanceledSubscriptionsSuccess.txt => ReportingFetchCanceledSubscriptionsSuccess.txt} (100%) rename tests/Mock/{FetchSubscriptionsFailure.txt => ReportingFetchSubscriptionsFailure.txt} (100%) rename tests/Mock/{FetchSubscriptionsSuccess.txt => ReportingFetchSubscriptionsSuccess.txt} (100%) rename tests/Mock/{FetchTransactionsFailure.txt => ReportingFetchTransactionsFailure.txt} (100%) rename tests/Mock/{FetchTransactionsSuccess.txt => ReportingFetchTransactionsSuccess.txt} (100%) diff --git a/tests/Message/FetchCanceledSubscriptionsRequestTest.php b/tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php similarity index 96% rename from tests/Message/FetchCanceledSubscriptionsRequestTest.php rename to tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php index 1a80b09..33a48c4 100644 --- a/tests/Message/FetchCanceledSubscriptionsRequestTest.php +++ b/tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php @@ -7,7 +7,7 @@ use DateTime; use DateTimeZone; -class FetchCanceledSubscriptionsRequestTest extends OmnipayBlueSnapTestCase +class ReportingFetchCanceledSubscriptionsRequestTest extends OmnipayBlueSnapTestCase { /** * @var DataFaker @@ -194,7 +194,7 @@ public function testSendSuccess() } } - $this->setMockHttpResponse('FetchCanceledSubscriptionsSuccess.txt', $replacements); + $this->setMockHttpResponse('ReportingFetchCanceledSubscriptionsSuccess.txt', $replacements); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); @@ -224,7 +224,7 @@ public function testSendFailure() $this->request->setStartTime($this->startTime); $this->request->setEndTime($this->endTime); - $this->setMockHttpResponse('FetchCanceledSubscriptionsFailure.txt'); + $this->setMockHttpResponse('ReportingFetchCanceledSubscriptionsFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); diff --git a/tests/Message/FetchSubscriptionsRequestTest.php b/tests/Message/ReportingFetchSubscriptionsRequestTest.php similarity index 95% rename from tests/Message/FetchSubscriptionsRequestTest.php rename to tests/Message/ReportingFetchSubscriptionsRequestTest.php index 4e05396..ebbbca3 100644 --- a/tests/Message/FetchSubscriptionsRequestTest.php +++ b/tests/Message/ReportingFetchSubscriptionsRequestTest.php @@ -8,7 +8,7 @@ use DateTimeZone; use Mockery; -class FetchSubscriptionsRequestTest extends OmnipayBlueSnapTestCase +class ReportingFetchSubscriptionsRequestTest extends OmnipayBlueSnapTestCase { /** * @var DataFaker @@ -151,7 +151,7 @@ public function testSendSuccess() } } - $this->setMockHttpResponse('FetchSubscriptionsSuccess.txt', $replacements); + $this->setMockHttpResponse('ReportingFetchSubscriptionsSuccess.txt', $replacements); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); @@ -181,7 +181,7 @@ public function testSendFailure() $this->request->setStartTime($this->startTime); $this->request->setEndTime($this->endTime); - $this->setMockHttpResponse('FetchSubscriptionsFailure.txt'); + $this->setMockHttpResponse('ReportingFetchSubscriptionsFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); diff --git a/tests/Message/FetchTransactionsRequestTest.php b/tests/Message/ReportingFetchTransactionsRequestTest.php similarity index 96% rename from tests/Message/FetchTransactionsRequestTest.php rename to tests/Message/ReportingFetchTransactionsRequestTest.php index 58d881d..6c6c51f 100644 --- a/tests/Message/FetchTransactionsRequestTest.php +++ b/tests/Message/ReportingFetchTransactionsRequestTest.php @@ -2,13 +2,11 @@ namespace Omnipay\BlueSnap\Message; -use Omnipay\BlueSnap\Test\Framework\OmnipayBlueSnapTestCase; -use Omnipay\BlueSnap\Test\Framework\DataFaker; use DateTime; -use DateTimeZone; -use Mockery; +use Omnipay\BlueSnap\Test\Framework\DataFaker; +use Omnipay\BlueSnap\Test\Framework\OmnipayBlueSnapTestCase; -class FetchTransactionsRequestTest extends OmnipayBlueSnapTestCase +class ReportingFetchTransactionsRequestTest extends OmnipayBlueSnapTestCase { /** * @var DataFaker @@ -155,7 +153,7 @@ public function testSendSuccess() } } - $this->setMockHttpResponse('FetchTransactionsSuccess.txt', $replacements); + $this->setMockHttpResponse('ReportingFetchTransactionsSuccess.txt', $replacements); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -186,7 +184,7 @@ public function testSendFailure() $this->request->setStartTime($this->startTime); $this->request->setEndTime($this->endTime); - $this->setMockHttpResponse('FetchTransactionsFailure.txt'); + $this->setMockHttpResponse('ReportingFetchTransactionsFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); diff --git a/tests/Mock/FetchCanceledSubscriptionsFailure.txt b/tests/Mock/ReportingFetchCanceledSubscriptionsFailure.txt similarity index 100% rename from tests/Mock/FetchCanceledSubscriptionsFailure.txt rename to tests/Mock/ReportingFetchCanceledSubscriptionsFailure.txt diff --git a/tests/Mock/FetchCanceledSubscriptionsSuccess.txt b/tests/Mock/ReportingFetchCanceledSubscriptionsSuccess.txt similarity index 100% rename from tests/Mock/FetchCanceledSubscriptionsSuccess.txt rename to tests/Mock/ReportingFetchCanceledSubscriptionsSuccess.txt diff --git a/tests/Mock/FetchSubscriptionsFailure.txt b/tests/Mock/ReportingFetchSubscriptionsFailure.txt similarity index 100% rename from tests/Mock/FetchSubscriptionsFailure.txt rename to tests/Mock/ReportingFetchSubscriptionsFailure.txt diff --git a/tests/Mock/FetchSubscriptionsSuccess.txt b/tests/Mock/ReportingFetchSubscriptionsSuccess.txt similarity index 100% rename from tests/Mock/FetchSubscriptionsSuccess.txt rename to tests/Mock/ReportingFetchSubscriptionsSuccess.txt diff --git a/tests/Mock/FetchTransactionsFailure.txt b/tests/Mock/ReportingFetchTransactionsFailure.txt similarity index 100% rename from tests/Mock/FetchTransactionsFailure.txt rename to tests/Mock/ReportingFetchTransactionsFailure.txt diff --git a/tests/Mock/FetchTransactionsSuccess.txt b/tests/Mock/ReportingFetchTransactionsSuccess.txt similarity index 100% rename from tests/Mock/FetchTransactionsSuccess.txt rename to tests/Mock/ReportingFetchTransactionsSuccess.txt From 926ad7c70a86c5819ac8b61042ae6a5b1bb709c4 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Tue, 19 Jan 2021 10:42:24 -0500 Subject: [PATCH 12/17] Fix phpcs issues --- src/Gateway.php | 4 +++- src/Message/ExtendedResponse.php | 3 ++- src/Message/Response.php | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index b3c8890..b005ee9 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -123,10 +123,12 @@ public function fetchSubscriptions(array $parameters = array()) */ public function fetchCanceledSubscriptions(array $parameters = array()) { + $class = '\Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest'; + /** * @var \Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest */ - return $this->createRequest('\Omnipay\BlueSnap\Message\ReportingFetchCanceledSubscriptionsRequest', $parameters); + return $this->createRequest($class, $parameters); } /** diff --git a/src/Message/ExtendedResponse.php b/src/Message/ExtendedResponse.php index 2535dec..582b664 100644 --- a/src/Message/ExtendedResponse.php +++ b/src/Message/ExtendedResponse.php @@ -396,7 +396,8 @@ public function getCard() /** * @var SimpleXMLElement */ - $contactXml = $this->invoice->{'financial-transactions'}->{'financial-transaction'}->{'invoice-contact-info'}; + $contactXml = $this->invoice->{'financial-transactions'}->{'financial-transaction'} + ->{'invoice-contact-info'}; if (isset($contactXml->{'first-name'})) { $cardParams['firstName'] = (string) $contactXml->{'first-name'}; } diff --git a/src/Message/Response.php b/src/Message/Response.php index d9931d1..1f73d26 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -20,9 +20,10 @@ class Response extends AbstractResponse /** * Retrieves multiple transactions data from the response. * - * This data can only be retrieved if the request was issued via @link ReportingFetchTransactionsRequest which uses the - * Reporting API. If the transaction data was retrieved via @link ExtendedFetchTransactionRequest this method will - * return null. To retrieve transaction data from the extended request see @link ExtendedResponse::getTransaction() + * This data can only be retrieved if the request was issued via @link ReportingFetchTransactionsRequest which + * uses the Reporting API. If the transaction data was retrieved via @link ExtendedFetchTransactionRequest this + * method will return null. To retrieve transaction data from the extended request see + * @link ExtendedResponse::getTransaction() * * @return array|null * @throws Exception From e2bb9852b445922847bfd752f7eb0eb7de543eff Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Tue, 19 Jan 2021 11:26:21 -0500 Subject: [PATCH 13/17] Use old array syntax --- src/Message/ExtendedResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/ExtendedResponse.php b/src/Message/ExtendedResponse.php index 582b664..a699513 100644 --- a/src/Message/ExtendedResponse.php +++ b/src/Message/ExtendedResponse.php @@ -432,14 +432,14 @@ public function getTransaction() if (!isset($this->transaction)) { $this->invoice = $this->getInvoice(); if ($this->invoice !== null) { - $params = [ + $params = array( 'amount' => $this->getAmount(), 'currency' => $this->getCurrency(), 'customerReference' => $this->getCustomerReference(), 'date' => $this->getDateCreated(), 'status' => $this->getStatus(), // Note chargebacks 'transactionReference' => $this->getTransactionReference(), - ]; + ); $this->transaction = new Transaction($params); } } From bd31eace538bdcbba5db59889d781d9807df45ec Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Tue, 19 Jan 2021 18:55:45 -0500 Subject: [PATCH 14/17] Map HostedCheckoutDecryptReturnUrlRequest to HostedCheckoutDecryptReturnUrlResponse --- .../HostedCheckoutDecryptReturnUrlRequest.php | 18 +++++++++++++ ...HostedCheckoutDecryptReturnUrlResponse.php | 26 +++++++++++++++++++ src/Message/Response.php | 16 ------------ 3 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 src/Message/HostedCheckoutDecryptReturnUrlResponse.php diff --git a/src/Message/HostedCheckoutDecryptReturnUrlRequest.php b/src/Message/HostedCheckoutDecryptReturnUrlRequest.php index 6b8aba0..5a7d952 100644 --- a/src/Message/HostedCheckoutDecryptReturnUrlRequest.php +++ b/src/Message/HostedCheckoutDecryptReturnUrlRequest.php @@ -52,6 +52,11 @@ */ class HostedCheckoutDecryptReturnUrlRequest extends AbstractRequest { + /** + * @var string + */ + protected static $RESPONSE_CLASS = '\Omnipay\BlueSnap\Message\HostedCheckoutDecryptReturnUrlResponse'; + /** * @return SimpleXMLElement * @psalm-suppress PossiblyInvalidArrayAccess because the existence of the key is checked first before using it. @@ -101,4 +106,17 @@ public function getHttpMethod() { return Constants::HTTP_METHOD_POST; } + + /** + * Overriding to provide a more precise return type + * + * @return HostedCheckoutDecryptReturnUrlResponse + */ + public function send() + { + /** + * @var HostedCheckoutDecryptReturnUrlResponse + */ + return parent::send(); + } } diff --git a/src/Message/HostedCheckoutDecryptReturnUrlResponse.php b/src/Message/HostedCheckoutDecryptReturnUrlResponse.php new file mode 100644 index 0000000..5584799 --- /dev/null +++ b/src/Message/HostedCheckoutDecryptReturnUrlResponse.php @@ -0,0 +1,26 @@ + paramValue + * + * @return array|null + * @psalm-suppress MixedPropertyFetch + */ + public function getDecryptedParameters() + { + if ($this->data instanceof SimpleXMLElement && isset($this->data->{'decrypted-token'})) { + parse_str((string) $this->data->{'decrypted-token'}, $result); + return $result ?: null; + } + return null; + } +} diff --git a/src/Message/Response.php b/src/Message/Response.php index 1f73d26..cf5f0de 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -85,20 +85,4 @@ public function getSubscriptions() } return $subscriptions; } - - /** - * Get the decrypted parameters from the return url after a HostedCheckoutDecryptReturnUrlRequest - * Returns an array of paramName => paramValue - * - * @return array|null - * @psalm-suppress MixedPropertyFetch - */ - public function getDecryptedParameters() - { - if ($this->data instanceof SimpleXMLElement && isset($this->data->{'decrypted-token'})) { - parse_str((string) $this->data->{'decrypted-token'}, $result); - return $result ?: null; - } - return null; - } } From d8f5e6f4a519682eecc42b026fd12ed17b3420c2 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Tue, 19 Jan 2021 19:08:17 -0500 Subject: [PATCH 15/17] rename response to ReportingResponse --- src/Message/AbstractRequest.php | 18 ++++++++++-------- src/Message/ExtendedResponse.php | 3 --- src/Message/ReportingAbstractRequest.php | 18 ++++++++++++++++++ .../{Response.php => ReportingResponse.php} | 7 +++---- 4 files changed, 31 insertions(+), 15 deletions(-) rename src/Message/{Response.php => ReportingResponse.php} (92%) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 82e1381..ae51ff8 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -25,14 +25,15 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest const XMLNS = 'http://ws.plimus.com'; /** - * @var Response + * @var string */ - protected $response; + protected static $RESPONSE_CLASS = '\Omnipay\BlueSnap\Message\AbstractResponse'; /** - * @var string + * @var AbstractResponse */ - protected static $RESPONSE_CLASS = '\Omnipay\BlueSnap\Message\Response'; + protected $response; + /** * Gets the username for making API calls @@ -305,7 +306,8 @@ protected function validateTimeZone(DateTime $datetime) * Makes the request * * @param SimpleXMLElement|null $data - * @return Response + * + * @return AbstractResponse * * @throws RuntimeException if $data is invalid XML * @throws Exception if there is a problem when initiating the request. @@ -391,7 +393,7 @@ function ($event) { } /** - * @var Response + * @var AbstractResponse */ $this->response = new static::$RESPONSE_CLASS($this, $responseData); @@ -425,12 +427,12 @@ public function validate() /** * Overriding to provide a more precise return type * - * @return Response + * @return AbstractResponse */ public function send() { /** - * @var Response + * @var AbstractResponse */ return parent::send(); } diff --git a/src/Message/ExtendedResponse.php b/src/Message/ExtendedResponse.php index a699513..9becf8b 100644 --- a/src/Message/ExtendedResponse.php +++ b/src/Message/ExtendedResponse.php @@ -245,9 +245,6 @@ public function getSubscriptions() * Note that chargeback and refund statuses are not store here. To see if a transaction contains a refund or a * chargeback refer to the following: * - * @see Response::getChargebacks() or - * @see Response::getRefunds() - * * @return string|null * @psalm-suppress MixedPropertyFetch */ diff --git a/src/Message/ReportingAbstractRequest.php b/src/Message/ReportingAbstractRequest.php index 476a922..d33d6e9 100644 --- a/src/Message/ReportingAbstractRequest.php +++ b/src/Message/ReportingAbstractRequest.php @@ -16,6 +16,11 @@ */ abstract class ReportingAbstractRequest extends AbstractRequest { + /** + * @var string + */ + protected static $RESPONSE_CLASS = '\Omnipay\BlueSnap\Message\ReportingResponse'; + /** * @return string */ @@ -31,6 +36,19 @@ public function getHttpMethod() return Constants::HTTP_METHOD_GET; } + /** + * Overriding to provide a more precise return type + * + * @return ReportingResponse + */ + public function send() + { + /** + * @var ReportingResponse + */ + return parent::send(); + } + /** * @return null * @throws InvalidRequestException diff --git a/src/Message/Response.php b/src/Message/ReportingResponse.php similarity index 92% rename from src/Message/Response.php rename to src/Message/ReportingResponse.php index cf5f0de..970ced7 100644 --- a/src/Message/Response.php +++ b/src/Message/ReportingResponse.php @@ -8,14 +8,13 @@ use Omnipay\BlueSnap\Constants; use Omnipay\BlueSnap\Subscription; use Omnipay\BlueSnap\Transaction; -use SimpleXMLElement; /** - * BlueSnap response object for the (non-extended) Payments API. See Request files or developer docs for usage. + * BlueSnap response object for the Reporting API. See Reporting*Request files or developer docs for usage. * - * @link https://developers.bluesnap.com/v8976-JSON/docs + * @link https://developers.bluesnap.com/v8976-Tools/docs/reporting-api-overview */ -class Response extends AbstractResponse +class ReportingResponse extends AbstractResponse { /** * Retrieves multiple transactions data from the response. From 289bbeecd6bf60cd174f8db55094b5241838c4c8 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Wed, 20 Jan 2021 13:47:32 -0500 Subject: [PATCH 16/17] Rename getMessage to getErrorMessage --- src/Message/AbstractResponse.php | 5 +++-- tests/Message/ExtendedCancelSubscriptionRequestTest.php | 4 ++-- tests/Message/ExtendedFetchCustomerRequestTest.php | 4 ++-- .../Message/ExtendedFetchSubscriptionChargeRequestTest.php | 4 ++-- tests/Message/ExtendedFetchSubscriptionRequestTest.php | 6 +++--- tests/Message/ExtendedFetchSubscriptionsRequestTest.php | 6 +++--- tests/Message/ExtendedFetchTransactionRequestTest.php | 6 +++--- tests/Message/ExtendedReactivateSubscriptionRequestTest.php | 4 ++-- tests/Message/ExtendedRefundRequestTest.php | 4 ++-- tests/Message/ExtendedTestChargeSubscriptionRequestTest.php | 4 ++-- tests/Message/ExtendedUpdateSubscriptionRequestTest.php | 4 ++-- tests/Message/HostedCheckoutDecryptReturnUrlRequestTest.php | 4 ++-- tests/Message/HostedCheckoutPurchaseRequestTest.php | 4 ++-- .../ReportingFetchCanceledSubscriptionsRequestTest.php | 4 ++-- tests/Message/ReportingFetchSubscriptionsRequestTest.php | 4 ++-- tests/Message/ReportingFetchTransactionsRequestTest.php | 4 ++-- 16 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index b25ba1b..8bed18a 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -113,12 +113,13 @@ public function getRequest() /** * Get the error message from the response. Returns null if request was successful. * - * Since this library works with both XML and JSON response data, this function checks for both types. + * A response error can is returned as XML if no application type is specified. We also need to account for JSON + * error responses returned as strings. * * @return string|null * @psalm-suppress MixedPropertyFetch because we check the data typing before using. */ - public function getMessage() + public function getErrorMessage() { if (!$this->isSuccessful()) { if ($this->data instanceof SimpleXMLElement && isset($this->data->message->description)) { diff --git a/tests/Message/ExtendedCancelSubscriptionRequestTest.php b/tests/Message/ExtendedCancelSubscriptionRequestTest.php index ee3af34..62a8c28 100644 --- a/tests/Message/ExtendedCancelSubscriptionRequestTest.php +++ b/tests/Message/ExtendedCancelSubscriptionRequestTest.php @@ -89,7 +89,7 @@ public function testSendSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('204', $response->getCode()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -110,7 +110,7 @@ public function testSendFailure() $this->assertSame( 'User API_1234567890123456789012 is not authorized to update subscription ID ' . $subscriptionReference . '.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ExtendedFetchCustomerRequestTest.php b/tests/Message/ExtendedFetchCustomerRequestTest.php index 13baba6..5ecaa64 100644 --- a/tests/Message/ExtendedFetchCustomerRequestTest.php +++ b/tests/Message/ExtendedFetchCustomerRequestTest.php @@ -86,7 +86,7 @@ public function testSendSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('200', $response->getCode()); $this->assertSame($this->customerReference, $response->getCustomerReference()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -103,7 +103,7 @@ public function testSendFailure() $this->assertSame('403', $response->getCode()); $this->assertSame( 'User: API_1234567890123456789012 is not authorized to view shopper: ' . $this->customerReference . '.', - $response->getMessage() + $response->getErrorMessage() ); } } diff --git a/tests/Message/ExtendedFetchSubscriptionChargeRequestTest.php b/tests/Message/ExtendedFetchSubscriptionChargeRequestTest.php index 59eda2a..feaa7c5 100644 --- a/tests/Message/ExtendedFetchSubscriptionChargeRequestTest.php +++ b/tests/Message/ExtendedFetchSubscriptionChargeRequestTest.php @@ -126,7 +126,7 @@ public function testSendSuccess() $responseDateCreated ? $responseDateCreated->getTimezone()->getName() : null ); $this->assertSame($transactionReference, $response->getTransactionReference()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -145,7 +145,7 @@ public function testSendFailure() $this->assertSame( 'Subscription Charge retrieval service failure because subscriptionCharge ID: ' . $this->subscriptionChargeReference . ' was not found.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ExtendedFetchSubscriptionRequestTest.php b/tests/Message/ExtendedFetchSubscriptionRequestTest.php index 3df1d6f..a448c98 100644 --- a/tests/Message/ExtendedFetchSubscriptionRequestTest.php +++ b/tests/Message/ExtendedFetchSubscriptionRequestTest.php @@ -149,7 +149,7 @@ public function testSendSuccess() } $this->assertSame($cardLastFour, $card->getNumberLastFour()); $this->assertSame($cardBrand, $card->getBrand()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -186,7 +186,7 @@ public function testSendWithOverriddenChargeSuccess() 'Etc/GMT+8', $responseNextChargeDate ? $responseNextChargeDate->getTimezone()->getName() : null ); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -236,7 +236,7 @@ public function testSendFailure() $this->assertSame( 'User API_1234567890123456789012 is not authorized to retrieve subscription ID ' . $this->subscriptionReference . '.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ExtendedFetchSubscriptionsRequestTest.php b/tests/Message/ExtendedFetchSubscriptionsRequestTest.php index df8c4be..0219249 100644 --- a/tests/Message/ExtendedFetchSubscriptionsRequestTest.php +++ b/tests/Message/ExtendedFetchSubscriptionsRequestTest.php @@ -128,8 +128,8 @@ public function testSendSuccess() $this->assertSame($fakeSubscription['AMOUNT'], $subscription->getAmount()); } } - $this->assertNull($response->getMessage()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -148,7 +148,7 @@ public function testSendFailure() $this->assertSame( 'User API_1234567890123456789012 is not authorized to retrieve subscription history for SHOPPER ID ' . $this->customerReference . '.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ExtendedFetchTransactionRequestTest.php b/tests/Message/ExtendedFetchTransactionRequestTest.php index 9ced923..ae3a1ff 100644 --- a/tests/Message/ExtendedFetchTransactionRequestTest.php +++ b/tests/Message/ExtendedFetchTransactionRequestTest.php @@ -159,7 +159,7 @@ public function testSendSuccess() $this->assertSame($email, $card->getEmail()); $this->assertSame($country, $card->getCountry()); $this->assertSame($postcode, $card->getPostcode()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -195,7 +195,7 @@ public function testSendMultipleInvoicesSuccess() 'Etc/GMT+8', $responseDateCreated ? $responseDateCreated->getTimezone()->getName() : null ); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -212,7 +212,7 @@ public function testSendFailure() $this->assertSame('400', $response->getCode()); $this->assertSame( 'Order retrieval service failure. Order ID: ' . $this->transactionReference . ' is not found.', - $response->getMessage() + $response->getErrorMessage() ); } } diff --git a/tests/Message/ExtendedReactivateSubscriptionRequestTest.php b/tests/Message/ExtendedReactivateSubscriptionRequestTest.php index c76e4e8..6fa75c1 100644 --- a/tests/Message/ExtendedReactivateSubscriptionRequestTest.php +++ b/tests/Message/ExtendedReactivateSubscriptionRequestTest.php @@ -87,7 +87,7 @@ public function testSendSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('204', $response->getCode()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -108,7 +108,7 @@ public function testSendFailure() $this->assertSame( 'User API_1234567890123456789012 is not authorized to update subscription ID ' . $subscriptionReference . '.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ExtendedRefundRequestTest.php b/tests/Message/ExtendedRefundRequestTest.php index dc422e6..4789b9b 100644 --- a/tests/Message/ExtendedRefundRequestTest.php +++ b/tests/Message/ExtendedRefundRequestTest.php @@ -175,7 +175,7 @@ public function testSendSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('204', $response->getCode()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -188,6 +188,6 @@ public function testSendFailure() $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('400', $response->getCode()); - $this->assertSame('Invoice has already been fully refunded.', $response->getMessage()); + $this->assertSame('Invoice has already been fully refunded.', $response->getErrorMessage()); } } diff --git a/tests/Message/ExtendedTestChargeSubscriptionRequestTest.php b/tests/Message/ExtendedTestChargeSubscriptionRequestTest.php index 18919c4..e31a7e1 100644 --- a/tests/Message/ExtendedTestChargeSubscriptionRequestTest.php +++ b/tests/Message/ExtendedTestChargeSubscriptionRequestTest.php @@ -100,7 +100,7 @@ public function testSendSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('204', $response->getCode()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -118,7 +118,7 @@ public function testSendFailure() // @codingStandardsIgnoreStart $this->assertSame( 'Call to runSpecificSubscription failed, subscriptionId ' . $this->subscriptionReference . '.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ExtendedUpdateSubscriptionRequestTest.php b/tests/Message/ExtendedUpdateSubscriptionRequestTest.php index 995126b..82bde35 100644 --- a/tests/Message/ExtendedUpdateSubscriptionRequestTest.php +++ b/tests/Message/ExtendedUpdateSubscriptionRequestTest.php @@ -120,7 +120,7 @@ public function testSendSuccess() $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('204', $response->getCode()); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -141,7 +141,7 @@ public function testSendFailure() $this->assertSame( 'The shopper: ' . $customerReference . ' has not given prior consent to certain' . ' additional charges and so this operation cannot be processed.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/HostedCheckoutDecryptReturnUrlRequestTest.php b/tests/Message/HostedCheckoutDecryptReturnUrlRequestTest.php index c1d8be0..656f6d0 100644 --- a/tests/Message/HostedCheckoutDecryptReturnUrlRequestTest.php +++ b/tests/Message/HostedCheckoutDecryptReturnUrlRequestTest.php @@ -137,7 +137,7 @@ public function testSendSuccess() ), $response->getDecryptedParameters() ); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -154,7 +154,7 @@ public function testSendFailure() $this->assertSame( 'Parameter Decryption service failed due to problematic input. We recommend checking' . ' the parameter-encyption token input and try again or contact merchant support.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/HostedCheckoutPurchaseRequestTest.php b/tests/Message/HostedCheckoutPurchaseRequestTest.php index 96e6488..175387d 100644 --- a/tests/Message/HostedCheckoutPurchaseRequestTest.php +++ b/tests/Message/HostedCheckoutPurchaseRequestTest.php @@ -209,7 +209,7 @@ public function testSendSuccess() 'https://sandbox.bluesnap.com/buynow/checkout?storeId=' . $this->storeReference . '&enc=' . $encryptedToken, $response->getRedirectUrl() ); - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -226,7 +226,7 @@ public function testSendFailure() $this->assertSame( 'Parameter Encryption service failed due to problematic input. Missing Data Protection Key: ' . 'please define it in the Console and try again.', - $response->getMessage() + $response->getErrorMessage() ); // @codingStandardsIgnoreEnd } diff --git a/tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php b/tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php index 33a48c4..ce122f6 100644 --- a/tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php +++ b/tests/Message/ReportingFetchCanceledSubscriptionsRequestTest.php @@ -213,7 +213,7 @@ public function testSendSuccess() $this->assertSame($fakeSubscription['AMOUNT'], $subscription->getAmount()); } } - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -229,6 +229,6 @@ public function testSendFailure() $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('400', $response->getCode()); - $this->assertSame('Invalid Date Range', $response->getMessage()); + $this->assertSame('Invalid Date Range', $response->getErrorMessage()); } } diff --git a/tests/Message/ReportingFetchSubscriptionsRequestTest.php b/tests/Message/ReportingFetchSubscriptionsRequestTest.php index ebbbca3..21ea4f3 100644 --- a/tests/Message/ReportingFetchSubscriptionsRequestTest.php +++ b/tests/Message/ReportingFetchSubscriptionsRequestTest.php @@ -170,7 +170,7 @@ public function testSendSuccess() $this->assertSame($fakeSubscription['AMOUNT'], $subscription->getAmount()); } } - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -186,6 +186,6 @@ public function testSendFailure() $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('400', $response->getCode()); - $this->assertSame('Invalid Date Range', $response->getMessage()); + $this->assertSame('Invalid Date Range', $response->getErrorMessage()); } } diff --git a/tests/Message/ReportingFetchTransactionsRequestTest.php b/tests/Message/ReportingFetchTransactionsRequestTest.php index 6c6c51f..f8ddd2b 100644 --- a/tests/Message/ReportingFetchTransactionsRequestTest.php +++ b/tests/Message/ReportingFetchTransactionsRequestTest.php @@ -173,7 +173,7 @@ public function testSendSuccess() $this->assertSame($fakeTransaction['CUSTOM_2'], $transaction->getCustomParameter2()); } } - $this->assertNull($response->getMessage()); + $this->assertNull($response->getErrorMessage()); } /** @@ -189,6 +189,6 @@ public function testSendFailure() $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('400', $response->getCode()); - $this->assertSame('Invalid Date Range', $response->getMessage()); + $this->assertSame('Invalid Date Range', $response->getErrorMessage()); } } From a0c4913ae1bb02c46f67e2426e378ffb695d1e12 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Wed, 20 Jan 2021 14:16:53 -0500 Subject: [PATCH 17/17] Typo fix --- src/Message/AbstractResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index 8bed18a..af8f23e 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -113,7 +113,7 @@ public function getRequest() /** * Get the error message from the response. Returns null if request was successful. * - * A response error can is returned as XML if no application type is specified. We also need to account for JSON + * A response error can be returned as XML if no content-type header is set. We also need to account for JSON * error responses returned as strings. * * @return string|null