From 902287afe0ff27fdeb0844189e79e88cd0109aaa Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 6 Mar 2017 23:20:29 +1300 Subject: [PATCH 01/35] Add getters and setters for hashSecret, an optional authorization parameter --- src/AIMGateway.php | 11 +++++++++++ src/SIMGateway.php | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/AIMGateway.php b/src/AIMGateway.php index 683ed160..6955017e 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -26,6 +26,7 @@ public function getDefaultParameters() 'transactionKey' => '', 'testMode' => false, 'developerMode' => false, + 'hashSecret' => '', 'liveEndpoint' => 'https://api2.authorize.net/xml/v1/request.api', 'developerEndpoint' => 'https://apitest.authorize.net/xml/v1/request.api', ); @@ -61,6 +62,16 @@ public function setDeveloperMode($value) return $this->setParameter('developerMode', $value); } + public function setHashSecret($value) + { + return $this->setParameter('hashSecret', $value); + } + + public function getHashSecret() + { + return $this->getParameter('hashSecret'); + } + public function setEndpoints($endpoints) { $this->setParameter('liveEndpoint', $endpoints['live']); diff --git a/src/SIMGateway.php b/src/SIMGateway.php index c5ccbe5c..67b47b4d 100644 --- a/src/SIMGateway.php +++ b/src/SIMGateway.php @@ -53,16 +53,6 @@ public function setDeveloperMode($value) return $this->setParameter('developerMode', $value); } - public function getHashSecret() - { - return $this->getParameter('hashSecret'); - } - - public function setHashSecret($value) - { - return $this->setParameter('hashSecret', $value); - } - public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters); From 90bceafa5a23bf86a668a2c5064a1148e7646ce9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 3 Oct 2017 21:03:36 +0300 Subject: [PATCH 02/35] Added solution id --- src/Message/AIMAbstractRequest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index d769f73d..167d71bb 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -100,6 +100,16 @@ public function getEndpoint() return $this->getDeveloperMode() ? $this->getDeveloperEndpoint() : $this->getLiveEndpoint(); } + public function getSolutionId() + { + return $this->getParameter('solutionId'); + } + + public function setSolutionId($value) + { + return $this->getSolutionId('solutionId', $value); + } + /** * @return TransactionReference */ @@ -220,6 +230,7 @@ public function getBaseData() $this->addAuthentication($data); $this->addReferenceId($data); $this->addTransactionType($data); + $this->addSolutiuonId($data); return $data; } @@ -249,6 +260,15 @@ protected function addTransactionType(\SimpleXMLElement $data) $data->transactionRequest->transactionType = $this->action; } + protected function addSolutiuonId(\SimpleXMLElement $data) + { + $solutionId = $this->getSolutionId(); + + if (!empty($solutionId)) { + $data->solution->id = $solutionId; + } + } + /** * Adds billing data to a partially filled request data object. * From 28503534e07642fb666e90e294d1b89ae600ddbd Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 3 Oct 2017 22:37:01 +0300 Subject: [PATCH 03/35] Added solution id --- src/Message/AIMAbstractRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 167d71bb..5f7c8010 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -107,7 +107,7 @@ public function getSolutionId() public function setSolutionId($value) { - return $this->getSolutionId('solutionId', $value); + return $this->setParameter('solutionId', $value); } /** From ab2ff86231e91164f51a2b3cb290333b2a417488 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 4 Oct 2017 12:31:56 +0300 Subject: [PATCH 04/35] Add solution id --- src/Message/AIMAbstractRequest.php | 3 +-- src/Message/AIMAuthorizeRequest.php | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 5f7c8010..34cf79af 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -230,7 +230,6 @@ public function getBaseData() $this->addAuthentication($data); $this->addReferenceId($data); $this->addTransactionType($data); - $this->addSolutiuonId($data); return $data; } @@ -260,7 +259,7 @@ protected function addTransactionType(\SimpleXMLElement $data) $data->transactionRequest->transactionType = $this->action; } - protected function addSolutiuonId(\SimpleXMLElement $data) + protected function addSolutionId(\SimpleXMLElement $data) { $solutionId = $this->getSolutionId(); diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index cdaed951..a4f0a58e 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -17,6 +17,7 @@ public function getData() $data = $this->getBaseData(); $data->transactionRequest->amount = $this->getAmount(); $this->addPayment($data); + $this->addSolutionId($data); $this->addBillingData($data); $this->addCustomerIP($data); $this->addTransactionSettings($data); From 7211453cade09d9fe50bbac8a7616f053ab10c5b Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 4 Oct 2017 12:52:08 +0300 Subject: [PATCH 05/35] Add solution id --- src/Message/AIMAbstractRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 34cf79af..660714f7 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -264,7 +264,7 @@ protected function addSolutionId(\SimpleXMLElement $data) $solutionId = $this->getSolutionId(); if (!empty($solutionId)) { - $data->solution->id = $solutionId; + $data->transactionRequest->solution->id = $solutionId; } } From b36d3c1d87fd67f0d5c5232f8b68bd6547a25019 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 4 Oct 2017 11:43:08 +0100 Subject: [PATCH 06/35] Remove PHP5.3 from failing travis tests. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4893becf..88558d85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 From af76ebd43254ee67f15c54de067648e2f5062a62 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Sat, 7 Oct 2017 11:41:16 +0100 Subject: [PATCH 07/35] Test solutionId for PR #87 --- tests/Message/AIMAbstractRequestTest.php | 15 +++++---------- tests/Message/AIMAuthorizeRequestTest.php | 5 ++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/Message/AIMAbstractRequestTest.php b/tests/Message/AIMAbstractRequestTest.php index 04d01400..03d47d32 100644 --- a/tests/Message/AIMAbstractRequestTest.php +++ b/tests/Message/AIMAbstractRequestTest.php @@ -1,25 +1,20 @@ request = $this->getMockForAbstractClass( - '\Omnipay\AuthorizeNet\Message\AIMAbstractRequest', - array( - $this->getMock('\Guzzle\Http\ClientInterface'), - $this->getMock('\Symfony\Component\HttpFoundation\Request') - ) - ); + $this->request = Mockery::mock('\Omnipay\AuthorizeNet\Message\AIMAbstractRequest')->makePartial(); + $this->request->initialize(); } public function testShouldReturnTransactionReference() diff --git a/tests/Message/AIMAuthorizeRequestTest.php b/tests/Message/AIMAuthorizeRequestTest.php index 611a5f2c..e410a8f5 100644 --- a/tests/Message/AIMAuthorizeRequestTest.php +++ b/tests/Message/AIMAuthorizeRequestTest.php @@ -20,7 +20,8 @@ public function setUp() 'amount' => '12.00', 'customerId' => 'cust-id', 'card' => $card, - 'duplicateWindow' => 0 + 'duplicateWindow' => 0, + 'solutionId' => 'SOL12345ID', ) ); } @@ -33,6 +34,7 @@ public function testGetData() $this->assertEquals('10.0.0.1', $data->transactionRequest->customerIP); $this->assertEquals('cust-id', $data->transactionRequest->customer->id); $this->assertEquals('example@example.net', $data->transactionRequest->customer->email); + $this->assertEquals('SOL12345ID', $data->transactionRequest->solution->id); // Issue #38 Make sure the transactionRequest properties are correctly ordered. // This feels messy, but works. @@ -43,6 +45,7 @@ public function testGetData() "transactionType", "amount", "payment", + "solution", "order", "customer", "billTo", From 235a0d5e8b42b65c3446ec0a1cbf8dcdfbf19161 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Sat, 7 Oct 2017 11:51:46 +0100 Subject: [PATCH 08/35] Add PHP 7.1 to the automated tests. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 88558d85..a910d105 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm matrix: From 821607495a2b72a4d412d6972ee8cf3efbba3e1d Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Sat, 7 Oct 2017 14:36:31 +0100 Subject: [PATCH 09/35] Test for PR #78 hashSecret set at AIM gateway level --- tests/AIMGatewayTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/AIMGatewayTest.php b/tests/AIMGatewayTest.php index e50a3823..827ccac0 100644 --- a/tests/AIMGatewayTest.php +++ b/tests/AIMGatewayTest.php @@ -19,6 +19,10 @@ public function setUp() $this->gateway = new AIMGateway($this->getHttpClient(), $this->getHttpRequest()); + $this->gateway->initialize([ + 'hashSecret' => 'HASHYsecretyThang', + ]); + $this->purchaseOptions = array( 'amount' => '10.00', 'card' => $this->getValidCard(), @@ -60,6 +64,15 @@ public function testDeveloperEndpoint() ); } + // Added for PR #78 + public function testHashSecret() + { + $this->assertEquals( + 'HASHYsecretyThang', + $this->gateway->getHashSecret() + ); + } + private function getExpiry($card) { return str_pad($card['expiryMonth'] . $card['expiryYear'], 6, '0', STR_PAD_LEFT); From ff9dc9d076ab44600a72d0669d7bd1ca90c649c7 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Sat, 7 Oct 2017 14:39:13 +0100 Subject: [PATCH 10/35] Extended PR #78 test to CIM gateway. --- tests/CIMGatewayTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/CIMGatewayTest.php b/tests/CIMGatewayTest.php index 9b3f9bfb..604f4707 100644 --- a/tests/CIMGatewayTest.php +++ b/tests/CIMGatewayTest.php @@ -20,6 +20,10 @@ public function setUp() $this->gateway = new CIMGateway($this->getHttpClient(), $this->getHttpRequest()); + $this->gateway->initialize([ + 'hashSecret' => 'HASHYsecretyThang', + ]); + $this->createCardOptions = array( 'email' => "kaylee@serenity.com", 'card' => $this->getValidCard(), @@ -62,6 +66,15 @@ public function testDeveloperEndpoint() ); } + // Added for PR #78 + public function testHashSecret() + { + $this->assertEquals( + 'HASHYsecretyThang', + $this->gateway->getHashSecret() + ); + } + public function testCreateCardSuccess() { $this->setMockHttpResponse(array('CIMCreateCardSuccess.txt','CIMGetPaymentProfileSuccess.txt')); From 30d1d1dd757f31526f6e47a547d0a3a055319a64 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 7 Mar 2017 00:06:23 +1300 Subject: [PATCH 11/35] Add actions for querying Authorize.net. These actions are intended to be generic & usable on other processors. The main ones are >$gateway = Omnipay::crete('AIMGateway'); >$gateway->query(array('startTimestamp' => strtotime('yesterday'), 'endTimeStamp' => 'strtotime('now'))); or for subscription plans: >$gateway->paymentPlansQuery(); The others are more internal. The response object for query() supports >$response->getFirstName(); >$response->getLastName(); >$response->getTransactionId(); // this is a standard transactionReference string, not the object >$response->getTransactionReference(); >$response->getBillingAddress1(); >$response->getBillingAddress2(); >$response->getBillingPostcode(); >$response->getBillingState(); >$response->getBillingCountry(); >$response->getBillingCity(); >$response->getAmount(); >$response->getEmail(); >$response->getDescription(); >$response->getCurrency(); // masked credit card number >$response->getNumber(); // Get card type >$response->getType(); >$response->getTransactionDate(); >$response->getTransactionDate(); >$response->getSettlementDate(); // Customer reference is a reference string for a contact created in the system. >$response->getCustomerReference(); // The recurring reference is a reference for the payment plan. >$response->getRecurringReference(); --- src/AIMGateway.php | 56 ++++ src/Message/AIMAbstractRequest.php | 1 + src/Message/AIMPaymentPlanQueryRequest.php | 94 +++++++ src/Message/AIMPaymentPlanQueryResponse.php | 136 ++++++++++ src/Message/AIMPaymentPlansQueryRequest.php | 83 ++++++ src/Message/AIMPaymentPlansQueryResponse.php | 71 +++++ src/Message/QueryBatchDetailRequest.php | 86 ++++++ src/Message/QueryBatchDetailResponse.php | 71 +++++ src/Message/QueryBatchRequest.php | 78 ++++++ src/Message/QueryBatchResponse.php | 82 ++++++ src/Message/QueryDetailRequest.php | 86 ++++++ src/Message/QueryDetailResponse.php | 271 +++++++++++++++++++ src/Message/QueryRequest.php | 73 +++++ src/Message/QueryResponse.php | 69 +++++ 14 files changed, 1257 insertions(+) create mode 100644 src/Message/AIMPaymentPlanQueryRequest.php create mode 100644 src/Message/AIMPaymentPlanQueryResponse.php create mode 100644 src/Message/AIMPaymentPlansQueryRequest.php create mode 100644 src/Message/AIMPaymentPlansQueryResponse.php create mode 100644 src/Message/QueryBatchDetailRequest.php create mode 100644 src/Message/QueryBatchDetailResponse.php create mode 100644 src/Message/QueryBatchRequest.php create mode 100644 src/Message/QueryBatchResponse.php create mode 100644 src/Message/QueryDetailRequest.php create mode 100644 src/Message/QueryDetailResponse.php create mode 100644 src/Message/QueryRequest.php create mode 100644 src/Message/QueryResponse.php diff --git a/src/AIMGateway.php b/src/AIMGateway.php index 6955017e..8f373d56 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -4,7 +4,9 @@ use Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest; use Omnipay\AuthorizeNet\Message\AIMCaptureRequest; +use Omnipay\AuthorizeNet\Message\AIMPaymentPlanQueryResponse; use Omnipay\AuthorizeNet\Message\AIMPurchaseRequest; +use Omnipay\AuthorizeNet\Message\QueryRequest; use Omnipay\AuthorizeNet\Message\AIMRefundRequest; use Omnipay\AuthorizeNet\Message\AIMVoidRequest; use Omnipay\Common\AbstractGateway; @@ -152,4 +154,58 @@ public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters); } + + /** + * @param array $parameters + * @return AIMPaymentPlansQueryRequest + */ + public function paymentPlansQuery(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPaymentPlansQueryRequest', $parameters); + } + + /** + * @param array $parameters + * @return AIMPaymentPlanQueryResponse + */ + public function paymentPlanQuery(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPaymentPlanQueryRequest', $parameters); + } + + /** + * @param array $parameters + * @return QueryResponse + */ + public function query(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryRequest', $parameters); + } + + /** + * @param array $parameters + * @return QueryBatchResponse + */ + public function queryBatch(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryBatchRequest', $parameters); + } + + /** + * @param array $parameters + * @return QueryBatchDetailResponse + */ + public function queryBatchDetail(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryBatchDetailRequest', $parameters); + } + + /** + * @param array $parameters + * @return QueryDetailResponse + */ + public function queryDetail(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryDetailRequest', $parameters); + } } diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 660714f7..2282e254 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -60,6 +60,7 @@ public function getHashSecret() { return $this->getParameter('hashSecret'); } + public function setHashSecret($value) { return $this->setParameter('hashSecret', $value); diff --git a/src/Message/AIMPaymentPlanQueryRequest.php b/src/Message/AIMPaymentPlanQueryRequest.php new file mode 100644 index 00000000..776dd0c1 --- /dev/null +++ b/src/Message/AIMPaymentPlanQueryRequest.php @@ -0,0 +1,94 @@ +recurringReference; + } + + /** + * @param string $recurringReference + */ + public function setRecurringReference($recurringReference) + { + $this->recurringReference = $recurringReference; + } + + /** + * Get Limit. + * + * @return int + */ + public function getLimit() + { + return $this->limit; + } + + /** + * Set Limit. + * + * @param int $limit + */ + public function setLimit($limit) + { + $this->limit = $limit; + } + + /** + * Get offset. + * + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * Set offset. + * + * @param int $offset + */ + public function setOffset($offset) + { + $this->offset = $offset; + } + + /** + * Get data to send. + */ + public function getData() + { + $data = $this->getBaseData(); + $data->subscriptionId = $this->getRecurringReference(); + return $data; + } + + protected function addTransactionType(\SimpleXMLElement $data) + { + } + + public function sendData($data) + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + return $this->response = new AIMPaymentPlanQueryResponse($this, $httpResponse->getBody()); + } +} diff --git a/src/Message/AIMPaymentPlanQueryResponse.php b/src/Message/AIMPaymentPlanQueryResponse.php new file mode 100644 index 00000000..4915ffe2 --- /dev/null +++ b/src/Message/AIMPaymentPlanQueryResponse.php @@ -0,0 +1,136 @@ +]+>/', '', (string)$data); + try { + $xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING); + } catch (\Exception $e) { + throw new InvalidResponseException(); + } + + if (!$xml) { + throw new InvalidResponseException(); + } + + parent::__construct($request, $xml); + $result = $this->xml2array($this->data->subscription, true); + $this->subscription = $result['subscription'][0]; + } + + public function isSuccessful() + { + return 1 === $this->getResultCode(); + } + + public function getData() + { + return $this->subscription; + } + + public function getRecurStartDate() + { + return $this->subscription['paymentSchedule']['interval']['startDate']; + } + + public function getRecurInstallmentLimit() + { + return $this->subscription['paymentSchedule']['interval']['totalOccurrences']; + } + + public function getRecurrenceInterval() + { + return $this->subscription['paymentSchedule']['interval'][0]['length']; + } + + public function getRecurAmount() + { + return $this->subscription['amount']; + } + + public function getRecurReference() + { + echo "he"; + print_r($this->subscription); + } + + public function getContactReference() + { + $profileID = $this->subscription['profile'][0]['customerProfileId']; + $gateway = $gateway = Omnipay::create('AuthorizeNet_CIM'); + $gateway->setApiLoginId($this->request->getApiLoginId()); + $gateway->setHashSecret($this->request->getHashSecret()); + $gateway->setTransactionKey($this->request->getTransactionKey()); + $data = array( + 'customerProfileId' => $profileID, + 'customerPaymentProfileId' => + $this->subscription['profile'][0]['paymentProfile'][0]['customerPaymentProfileId'], + ); + $dataResponse = $gateway->getProfile($data)->send(); + return $dataResponse->getCustomerId(); + } + + /** + * @todo formalise options. + * + * @return mixed + */ + public function getRecurStatus() + { + return $this->subscription['paymentSchedule']['interval'][0]['status']; + } + + public function getRecurrenceUnit() + { + $interval = $this->subscription['paymentSchedule']['interval'][0]['unit']; + $options = array( + 'months' => 'month', + ); + return $options[$interval]; + } + + /** + * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ + * + * Convert a simpleXMLElement in to an array + * + * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. + * + * @param \SimpleXMLElement $xml + * + * @return array + */ + public function xml2array(\SimpleXMLElement $xml) + { + $arr = array(); + foreach ($xml as $element) { + $tag = $element->getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} diff --git a/src/Message/AIMPaymentPlansQueryRequest.php b/src/Message/AIMPaymentPlansQueryRequest.php new file mode 100644 index 00000000..abdca244 --- /dev/null +++ b/src/Message/AIMPaymentPlansQueryRequest.php @@ -0,0 +1,83 @@ +limit; + } + + /** + * Set Limit. + * + * @param int $limit + */ + public function setLimit($limit) + { + $this->limit = $limit; + } + + /** + * Get offset. + * + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * Set offset. + * + * @param int $offset + */ + public function setOffset($offset) + { + $this->offset = $offset; + } + + /** + * Get data to send. + */ + public function getData() + { + $data = $this->getBaseData(); + $data->searchType = 'subscriptionActive'; + $data->sorting->orderBy = 'id'; + $data->sorting->orderDescending = true; + $data->paging->limit = $this->getLimit(); + $data->paging->offset = $this->getOffset(); + return $data; + } + + protected function addTransactionType(\SimpleXMLElement $data) + { + } + + public function sendData($data) + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + return $this->response = new AIMPaymentPlansQueryResponse($this, $httpResponse->getBody()); + } +} diff --git a/src/Message/AIMPaymentPlansQueryResponse.php b/src/Message/AIMPaymentPlansQueryResponse.php new file mode 100644 index 00000000..857479f5 --- /dev/null +++ b/src/Message/AIMPaymentPlansQueryResponse.php @@ -0,0 +1,71 @@ +]+>/', '', (string)$data); + + try { + $xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING); + } catch (\Exception $e) { + throw new InvalidResponseException(); + } + + if (!$xml) { + throw new InvalidResponseException(); + } + + parent::__construct($request, $xml); + } + + public function isSuccessful() + { + return 1 === $this->getResultCode(); + } + + public function getPlanData() + { + $result = $this->xml2array($this->data->subscriptionDetails, true); + return $result['subscriptionDetails'][0]['subscriptionDetail']; + } + + /** + * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ + * + * Convert a simpleXMLElement in to an array + * + * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. + * + * @param \SimpleXMLElement $xml + * + * @return array + */ + public function xml2array(\SimpleXMLElement $xml) + { + $arr = array(); + foreach ($xml as $element) { + $tag = $element->getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} diff --git a/src/Message/QueryBatchDetailRequest.php b/src/Message/QueryBatchDetailRequest.php new file mode 100644 index 00000000..aeb7e5e0 --- /dev/null +++ b/src/Message/QueryBatchDetailRequest.php @@ -0,0 +1,86 @@ +limit; + } + + /** + * Set Limit. + * + * @param int $limit + */ + public function setLimit($limit) + { + $this->limit = $limit; + } + + /** + * Get offset. + * + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * Set offset. + * + * @param int $offset + */ + public function setOffset($offset) + { + $this->offset = $offset; + } + + /** + * Get data to send. + */ + public function getData() + { + $data = $this->getBaseData(); + $data->batchId = $this->getBatchID(); + return $data; + } + + public function sendData($data) + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + return $this->response = new QueryBatchDetailResponse($this, $httpResponse->getBody()); + } + + public function setBatchID($batchID) + { + $this->batchID = $batchID; + } + + public function getBatchID() + { + return $this->batchID; + } +} diff --git a/src/Message/QueryBatchDetailResponse.php b/src/Message/QueryBatchDetailResponse.php new file mode 100644 index 00000000..e8eaa726 --- /dev/null +++ b/src/Message/QueryBatchDetailResponse.php @@ -0,0 +1,71 @@ +]+>/', '', (string)$data); + try { + $xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING); + } catch (\Exception $e) { + throw new InvalidResponseException(); + } + + if (!$xml) { + throw new InvalidResponseException(); + } + + parent::__construct($request, $xml); + } + + public function isSuccessful() + { + return 1 === $this->getResultCode(); + } + + public function getData() + { + $result = $this->xml2array($this->data->transactions, true); + return $result['transactions'][0]['transaction']; + } + + /** + * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ + * + * Convert a simpleXMLElement in to an array + * + * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. + * + * @param \SimpleXMLElement $xml + * + * @return array + */ + public function xml2array(\SimpleXMLElement $xml) + { + $arr = array(); + foreach ($xml as $element) { + $tag = $element->getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} diff --git a/src/Message/QueryBatchRequest.php b/src/Message/QueryBatchRequest.php new file mode 100644 index 00000000..14e8a6f5 --- /dev/null +++ b/src/Message/QueryBatchRequest.php @@ -0,0 +1,78 @@ +limit; + } + + /** + * Set Limit. + * + * @param int $limit + */ + public function setLimit($limit) + { + $this->limit = $limit; + } + + /** + * Get offset. + * + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * Set offset. + * + * @param int $offset + */ + public function setOffset($offset) + { + $this->offset = $offset; + } + + /** + * Get data to send. + */ + public function getData() + { + $data = $this->getBaseData(); + return $data; + } + + protected function addTransactionType(\SimpleXMLElement $data) + { + } + + public function sendData($data) + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + return $this->response = new QueryBatchResponse($this, $httpResponse->getBody()); + } +} diff --git a/src/Message/QueryBatchResponse.php b/src/Message/QueryBatchResponse.php new file mode 100644 index 00000000..41a6881b --- /dev/null +++ b/src/Message/QueryBatchResponse.php @@ -0,0 +1,82 @@ +]+>/', '', (string)$data); + + try { + $xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING); + } catch (\Exception $e) { + throw new InvalidResponseException(); + } + + if (!$xml) { + throw new InvalidResponseException(); + } + + parent::__construct($request, $xml); + } + + public function isSuccessful() + { + return 'Ok' === $this->getResultCode(); + } + + public function getResultCode() + { + $result = $this->xml2array($this->data->messages, true); + return $result['messages'][0]['resultCode']; + } + + public function getData() + { + $result = $this->xml2array($this->data->batchList, true); + return $result['batchList'][0]['batch']; + } + + /** + * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ + * + * Convert a simpleXMLElement in to an array + * + * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. + * + * @param \SimpleXMLElement $xml + * + * @return array + */ + public function xml2array(\SimpleXMLElement $xml) + { + $arr = array(); + foreach ($xml as $element) { + $tag = $element->getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} diff --git a/src/Message/QueryDetailRequest.php b/src/Message/QueryDetailRequest.php new file mode 100644 index 00000000..132e3524 --- /dev/null +++ b/src/Message/QueryDetailRequest.php @@ -0,0 +1,86 @@ +limit; + } + + /** + * Set Limit. + * + * @param int $limit + */ + public function setLimit($limit) + { + $this->limit = $limit; + } + + /** + * Get offset. + * + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * Set offset. + * + * @param int $offset + */ + public function setOffset($offset) + { + $this->offset = $offset; + } + + /** + * Get data to send. + */ + public function getData() + { + $data = $this->getBaseData(); + $data->transId = $this->getTransactionReference(); + return $data; + } + + public function sendData($data) + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + return $this->response = new QueryDetailResponse($this, $httpResponse->getBody()); + } + + public function setTransactionReference($transactionReference) + { + $this->transactionReference = $transactionReference; + } + + public function getTransactionReference() + { + return $this->transactionReference; + } +} diff --git a/src/Message/QueryDetailResponse.php b/src/Message/QueryDetailResponse.php new file mode 100644 index 00000000..8393dd13 --- /dev/null +++ b/src/Message/QueryDetailResponse.php @@ -0,0 +1,271 @@ +]+>/', '', (string)$data); + + try { + $xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING); + } catch (\Exception $e) { + throw new InvalidResponseException(); + } + + if (!$xml) { + throw new InvalidResponseException(); + } + + parent::__construct($request, $xml); + $result = $this->xml2array($this->data->transaction, true); + $this->transaction = $result['transaction'][0]; + } + + public function isSuccessful() + { + return 1 == $this->getResultCode(); + } + + + public function isRecurring() + { + return ($this->transaction['recurringBilling'] === 'true'); + } + + public function getClientIp() + { + return $this->transaction['customerIP']; + } + + /** + * TransactionReference is the reference generated by the payment gateway. + * + * @return mixed + */ + public function getTransactionReference() + { + return $this->transaction['transId']; + } + + /** + * TransactionId is the reference set by the originating website. + * + * @return mixed + */ + public function getTransactionId() + { + return $this->transaction['order'][0]['invoiceNumber']; + } + + public function getAmount() + { + return $this->transaction['settleAmount']; + } + + public function getDescription() + { + return $this->transaction['order'][0]['description']; + } + + /** + * Get email. + * + * @return string + */ + public function getEmail() + { + return $this->transaction['customer'][0]['email']; + } + + public function getResultCode() + { + return $this->transaction['responseCode']; + } + + /** + * Get the currency. + * + * Seems to onlys support USD. + * + * @return string + */ + public function getCurrency() + { + return 'USD'; + } + + /** + * Get first name. + * + * In practice this is billing first name. + * + * @return string + */ + public function getFirstName() + { + return $this->transaction['billTo'][0]['firstName']; + } + + /** + * Get the gateway generated id for the recurring transaction. + */ + public function getRecurringReference() + { + return $this->transaction['subscription'][0]['id']; + } + + /** + * Get the gateway generated id for the recurring transaction. + */ + public function getCustomerReference() + { + if (!$this->isRecurring()) { + return ''; + } + if (!$this->planResponse) { + /** @var \Omnipay\AuthorizeNet\AIMGateway $gateway */ + $gateway = Omnipay::create('AuthorizeNet_AIM'); + $gateway->setApiLoginId($this->request->getApiLoginId()); + $gateway->setHashSecret($this->request->getHashSecret()); + $gateway->setTransactionKey($this->request->getTransactionKey()); + $data = array('recurringReference' => $this->getRecurringReference()); + $this->planResponse = $gateway->paymentPlanQuery($data)->send(); + } + return $this->planResponse->getContactReference(); + + + } + + /** + * Get last name. + * + * In practice this is billing last name. + * + * @return string + */ + public function getLastName() + { + return $this->transaction['billTo'][0]['lastName']; + } + + /** + * Get credit card number. + * + * This is masked. Is this the correct parameter name. + */ + public function getNumber() + { + return $this->transaction['payment'][0]['creditCard'][0]['cardNumber']; + } + + public function getType() + { + return $this->transaction['payment'][0]['creditCard'][0]['cardType']; + } + + public function getBillingAddress1() + { + return $this->transaction['billTo'][0]['address']; + } + + public function getBillingAddress2() + { + return ''; + } + + public function getBillingCity() + { + return $this->transaction['billTo'][0]['city']; + } + + public function getBillingPostcode() + { + return $this->transaction['billTo'][0]['zip']; + } + + /** + * Get billing address State. + * + * @todo consider if there should be other variants for full vs abbreviation. + * + * @return mixed + */ + public function getBillingState() + { + return $this->transaction['billTo'][0]['state']; + } + + /** + * Get billing address Country. + * + * @todo consider if there should be other variants for full vs abbreviation. + * + * @return mixed + */ + public function getBillingCountry() + { + return $this->transaction['billTo'][0]['country']; + } + + /** + * Get transaction date in UTC. + * + * @return string + */ + public function getSettlementDate() + { + return $this->transaction['batch'][0]['settlementTimeUTC']; + } + + /** + * Get settlement date in UTC. + * + * @return string + */ + public function getTransactionDate() + { + return $this->transaction['submitTimeUTC']; + } + + /** + * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ + * + * Convert a simpleXMLElement in to an array + * + * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. + * + * @param \SimpleXMLElement $xml + * + * @return array + */ + public function xml2array(\SimpleXMLElement $xml) + { + $arr = array(); + foreach ($xml as $element) { + $tag = $element->getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} diff --git a/src/Message/QueryRequest.php b/src/Message/QueryRequest.php new file mode 100644 index 00000000..ea678a68 --- /dev/null +++ b/src/Message/QueryRequest.php @@ -0,0 +1,73 @@ +startTimestamp; + } + + /** + * @param mixed $startTimestamp + */ + public function setStartTimestamp($startTimestamp) + { + $this->startTimestamp = $startTimestamp; + } + + /** + * @return mixed + */ + public function getEndTimestamp() + { + return $this->endTimestamp; + } + + /** + * @param mixed $endTimestamp + */ + public function setEndTimestamp($endTimestamp) + { + $this->endTimestamp = $endTimestamp; + } + + /** + * Get data to send. + */ + public function getData() + { + $data = $this->getBaseData(); + if ($this->getStartTimestamp()) { + $data->firstSettlementDate = date('Y-m-d\Th:i:s\Z', $this->getStartTimestamp()); + $data->lastSettlementDate = date('Y-m-d\Th:i:s\Z'); + } + if ($this->getEndTimestamp()) { + $data->lastSettlementDate = date('Y-m-d\Th:i:s\Z', $this->getEndTimestamp()); + } + return $data; + } + + public function sendData($data) + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + $this->response = new QueryResponse($this, $httpResponse->getBody()); + return $this->response; + } +} diff --git a/src/Message/QueryResponse.php b/src/Message/QueryResponse.php new file mode 100644 index 00000000..86122bea --- /dev/null +++ b/src/Message/QueryResponse.php @@ -0,0 +1,69 @@ +setApiLoginId($this->request->getApiLoginId()); + $gateway->setHashSecret($this->request->getHashSecret()); + $gateway->setTransactionKey($this->request->getTransactionKey()); + $gateway->setDeveloperMode($this->request->getDeveloperMode()); + $data = array('batch_id' => $batch['batchId']); + $dataResponse = $gateway->queryBatchDetail($data)->send(); + $transactions = $dataResponse->getData(); + foreach ($transactions as $transaction) { + $detailResponse = $gateway->queryDetail(array('transactionReference' => $transaction['transId'])) + ->send(); + $result[] = $detailResponse; + } + } + } + return $result; + } + + /** + * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ + * + * Convert a simpleXMLElement in to an array + * + * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. + * + * @param \SimpleXMLElement $xml + * + * @return array + */ + public function xml2array(\SimpleXMLElement $xml) + { + $arr = array(); + foreach ($xml as $element) { + $tag = $element->getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} From 0388163b0fff4d4fbc1baaae51aef37c958ad307 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 7 Nov 2017 09:04:27 +1300 Subject: [PATCH 12/35] Add parent classes into query requests & responses, folderise #79 --- .editorconfig | 14 ++++++ src/AIMGateway.php | 4 +- .../AIMAbstractQueryRequest.php} | 23 ++-------- .../AIMPaymentPlanQueryRequest.php | 44 +------------------ .../AIMPaymentPlanQueryResponse.php | 7 ++- .../AIMPaymentPlansQueryRequest.php | 32 +------------- .../AIMPaymentPlansQueryResponse.php | 31 +------------ src/Message/Query/AbstractQueryResponse.php | 43 ++++++++++++++++++ .../{ => Query}/QueryBatchDetailRequest.php | 42 +----------------- .../{ => Query}/QueryBatchDetailResponse.php | 31 +------------ src/Message/Query/QueryBatchRequest.php | 23 ++++++++++ .../{ => Query}/QueryBatchResponse.php | 31 +------------ .../{ => Query}/QueryDetailRequest.php | 44 +------------------ .../{ => Query}/QueryDetailResponse.php | 31 +------------ src/Message/{ => Query}/QueryRequest.php | 2 +- src/Message/{ => Query}/QueryResponse.php | 29 +----------- 16 files changed, 103 insertions(+), 328 deletions(-) create mode 100644 .editorconfig rename src/Message/{QueryBatchRequest.php => Query/AIMAbstractQueryRequest.php} (54%) rename src/Message/{ => Query}/AIMPaymentPlanQueryRequest.php (63%) rename src/Message/{ => Query}/AIMPaymentPlanQueryResponse.php (96%) rename src/Message/{ => Query}/AIMPaymentPlansQueryRequest.php (72%) rename src/Message/{ => Query}/AIMPaymentPlansQueryResponse.php (57%) create mode 100644 src/Message/Query/AbstractQueryResponse.php rename src/Message/{ => Query}/QueryBatchDetailRequest.php (62%) rename src/Message/{ => Query}/QueryBatchDetailResponse.php (56%) create mode 100644 src/Message/Query/QueryBatchRequest.php rename src/Message/{ => Query}/QueryBatchResponse.php (63%) rename src/Message/{ => Query}/QueryDetailRequest.php (61%) rename src/Message/{ => Query}/QueryDetailResponse.php (86%) rename src/Message/{ => Query}/QueryRequest.php (97%) rename src/Message/{ => Query}/QueryResponse.php (64%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..0c9db577 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# CiviCRM editor configuration normalization +# @see http://editorconfig.org/ + +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/src/AIMGateway.php b/src/AIMGateway.php index 8f373d56..8295d2bc 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -161,7 +161,7 @@ public function refund(array $parameters = array()) */ public function paymentPlansQuery(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPaymentPlansQueryRequest', $parameters); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\Query\AIMPaymentPlansQueryRequest', $parameters); } /** @@ -170,7 +170,7 @@ public function paymentPlansQuery(array $parameters = array()) */ public function paymentPlanQuery(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPaymentPlanQueryRequest', $parameters); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\Query\AIMPaymentPlanQueryRequest', $parameters); } /** diff --git a/src/Message/QueryBatchRequest.php b/src/Message/Query/AIMAbstractQueryRequest.php similarity index 54% rename from src/Message/QueryBatchRequest.php rename to src/Message/Query/AIMAbstractQueryRequest.php index 14e8a6f5..560dd006 100644 --- a/src/Message/QueryBatchRequest.php +++ b/src/Message/Query/AIMAbstractQueryRequest.php @@ -1,16 +1,12 @@ getBaseData(); return $data; } - - protected function addTransactionType(\SimpleXMLElement $data) - { - } - - public function sendData($data) - { - $headers = array('Content-Type' => 'text/xml; charset=utf-8'); - $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); - - return $this->response = new QueryBatchResponse($this, $httpResponse->getBody()); - } } diff --git a/src/Message/AIMPaymentPlanQueryRequest.php b/src/Message/Query/AIMPaymentPlanQueryRequest.php similarity index 63% rename from src/Message/AIMPaymentPlanQueryRequest.php rename to src/Message/Query/AIMPaymentPlanQueryRequest.php index 776dd0c1..d1a58a4b 100644 --- a/src/Message/AIMPaymentPlanQueryRequest.php +++ b/src/Message/Query/AIMPaymentPlanQueryRequest.php @@ -1,13 +1,13 @@ recurringReference = $recurringReference; } - /** - * Get Limit. - * - * @return int - */ - public function getLimit() - { - return $this->limit; - } - - /** - * Set Limit. - * - * @param int $limit - */ - public function setLimit($limit) - { - $this->limit = $limit; - } - - /** - * Get offset. - * - * @return int - */ - public function getOffset() - { - return $this->offset; - } - - /** - * Set offset. - * - * @param int $offset - */ - public function setOffset($offset) - { - $this->offset = $offset; - } - /** * Get data to send. */ diff --git a/src/Message/AIMPaymentPlanQueryResponse.php b/src/Message/Query/AIMPaymentPlanQueryResponse.php similarity index 96% rename from src/Message/AIMPaymentPlanQueryResponse.php rename to src/Message/Query/AIMPaymentPlanQueryResponse.php index 4915ffe2..167f73f7 100644 --- a/src/Message/AIMPaymentPlanQueryResponse.php +++ b/src/Message/Query/AIMPaymentPlanQueryResponse.php @@ -1,6 +1,6 @@ subscription); + return $this->subscription; } public function getContactReference() diff --git a/src/Message/AIMPaymentPlansQueryRequest.php b/src/Message/Query/AIMPaymentPlansQueryRequest.php similarity index 72% rename from src/Message/AIMPaymentPlansQueryRequest.php rename to src/Message/Query/AIMPaymentPlansQueryRequest.php index abdca244..13afb190 100644 --- a/src/Message/AIMPaymentPlansQueryRequest.php +++ b/src/Message/Query/AIMPaymentPlansQueryRequest.php @@ -1,6 +1,6 @@ limit; } - /** - * Set Limit. - * - * @param int $limit - */ - public function setLimit($limit) - { - $this->limit = $limit; - } - - /** - * Get offset. - * - * @return int - */ - public function getOffset() - { - return $this->offset; - } - - /** - * Set offset. - * - * @param int $offset - */ - public function setOffset($offset) - { - $this->offset = $offset; - } - /** * Get data to send. */ diff --git a/src/Message/AIMPaymentPlansQueryResponse.php b/src/Message/Query/AIMPaymentPlansQueryResponse.php similarity index 57% rename from src/Message/AIMPaymentPlansQueryResponse.php rename to src/Message/Query/AIMPaymentPlansQueryResponse.php index 857479f5..c0830f90 100644 --- a/src/Message/AIMPaymentPlansQueryResponse.php +++ b/src/Message/Query/AIMPaymentPlansQueryResponse.php @@ -1,6 +1,6 @@ xml2array($this->data->subscriptionDetails, true); return $result['subscriptionDetails'][0]['subscriptionDetail']; } - - /** - * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ - * - * Convert a simpleXMLElement in to an array - * - * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. - * - * @param \SimpleXMLElement $xml - * - * @return array - */ - public function xml2array(\SimpleXMLElement $xml) - { - $arr = array(); - foreach ($xml as $element) { - $tag = $element->getName(); - $e = get_object_vars($element); - if (!empty($e)) { - $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; - } else { - $arr[$tag] = trim($element); - } - } - - return $arr; - } } diff --git a/src/Message/Query/AbstractQueryResponse.php b/src/Message/Query/AbstractQueryResponse.php new file mode 100644 index 00000000..b4414fdb --- /dev/null +++ b/src/Message/Query/AbstractQueryResponse.php @@ -0,0 +1,43 @@ +getName(); + $e = get_object_vars($element); + if (!empty($e)) { + $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; + } else { + $arr[$tag] = trim($element); + } + } + + return $arr; + } +} diff --git a/src/Message/QueryBatchDetailRequest.php b/src/Message/Query/QueryBatchDetailRequest.php similarity index 62% rename from src/Message/QueryBatchDetailRequest.php rename to src/Message/Query/QueryBatchDetailRequest.php index aeb7e5e0..98d0d1c8 100644 --- a/src/Message/QueryBatchDetailRequest.php +++ b/src/Message/Query/QueryBatchDetailRequest.php @@ -1,6 +1,6 @@ limit; - } - - /** - * Set Limit. - * - * @param int $limit - */ - public function setLimit($limit) - { - $this->limit = $limit; - } - - /** - * Get offset. - * - * @return int - */ - public function getOffset() - { - return $this->offset; - } - - /** - * Set offset. - * - * @param int $offset - */ - public function setOffset($offset) - { - $this->offset = $offset; - } - /** * Get data to send. */ diff --git a/src/Message/QueryBatchDetailResponse.php b/src/Message/Query/QueryBatchDetailResponse.php similarity index 56% rename from src/Message/QueryBatchDetailResponse.php rename to src/Message/Query/QueryBatchDetailResponse.php index e8eaa726..6d89bf70 100644 --- a/src/Message/QueryBatchDetailResponse.php +++ b/src/Message/Query/QueryBatchDetailResponse.php @@ -1,6 +1,6 @@ xml2array($this->data->transactions, true); return $result['transactions'][0]['transaction']; } - - /** - * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ - * - * Convert a simpleXMLElement in to an array - * - * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. - * - * @param \SimpleXMLElement $xml - * - * @return array - */ - public function xml2array(\SimpleXMLElement $xml) - { - $arr = array(); - foreach ($xml as $element) { - $tag = $element->getName(); - $e = get_object_vars($element); - if (!empty($e)) { - $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; - } else { - $arr[$tag] = trim($element); - } - } - - return $arr; - } } diff --git a/src/Message/Query/QueryBatchRequest.php b/src/Message/Query/QueryBatchRequest.php new file mode 100644 index 00000000..87f0fb3e --- /dev/null +++ b/src/Message/Query/QueryBatchRequest.php @@ -0,0 +1,23 @@ + 'text/xml; charset=utf-8'); + $data = $data->saveXml(); + $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + + return $this->response = new QueryBatchResponse($this, $httpResponse->getBody()); + } +} diff --git a/src/Message/QueryBatchResponse.php b/src/Message/Query/QueryBatchResponse.php similarity index 63% rename from src/Message/QueryBatchResponse.php rename to src/Message/Query/QueryBatchResponse.php index 41a6881b..32995dab 100644 --- a/src/Message/QueryBatchResponse.php +++ b/src/Message/Query/QueryBatchResponse.php @@ -1,6 +1,6 @@ xml2array($this->data->batchList, true); return $result['batchList'][0]['batch']; } - - /** - * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ - * - * Convert a simpleXMLElement in to an array - * - * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. - * - * @param \SimpleXMLElement $xml - * - * @return array - */ - public function xml2array(\SimpleXMLElement $xml) - { - $arr = array(); - foreach ($xml as $element) { - $tag = $element->getName(); - $e = get_object_vars($element); - if (!empty($e)) { - $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; - } else { - $arr[$tag] = trim($element); - } - } - - return $arr; - } } diff --git a/src/Message/QueryDetailRequest.php b/src/Message/Query/QueryDetailRequest.php similarity index 61% rename from src/Message/QueryDetailRequest.php rename to src/Message/Query/QueryDetailRequest.php index 132e3524..7b2034de 100644 --- a/src/Message/QueryDetailRequest.php +++ b/src/Message/Query/QueryDetailRequest.php @@ -1,6 +1,6 @@ limit; - } - - /** - * Set Limit. - * - * @param int $limit - */ - public function setLimit($limit) - { - $this->limit = $limit; - } - - /** - * Get offset. - * - * @return int - */ - public function getOffset() - { - return $this->offset; - } - - /** - * Set offset. - * - * @param int $offset - */ - public function setOffset($offset) - { - $this->offset = $offset; - } - /** * Get data to send. */ diff --git a/src/Message/QueryDetailResponse.php b/src/Message/Query/QueryDetailResponse.php similarity index 86% rename from src/Message/QueryDetailResponse.php rename to src/Message/Query/QueryDetailResponse.php index 8393dd13..cb151f1e 100644 --- a/src/Message/QueryDetailResponse.php +++ b/src/Message/Query/QueryDetailResponse.php @@ -1,6 +1,6 @@ transaction['submitTimeUTC']; } - - /** - * http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/ - * - * Convert a simpleXMLElement in to an array - * - * @todo this is duplicated from CIMAbstractResponse. Put somewhere shared. - * - * @param \SimpleXMLElement $xml - * - * @return array - */ - public function xml2array(\SimpleXMLElement $xml) - { - $arr = array(); - foreach ($xml as $element) { - $tag = $element->getName(); - $e = get_object_vars($element); - if (!empty($e)) { - $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; - } else { - $arr[$tag] = trim($element); - } - } - - return $arr; - } } diff --git a/src/Message/QueryRequest.php b/src/Message/Query/QueryRequest.php similarity index 97% rename from src/Message/QueryRequest.php rename to src/Message/Query/QueryRequest.php index ea678a68..88118160 100644 --- a/src/Message/QueryRequest.php +++ b/src/Message/Query/QueryRequest.php @@ -1,6 +1,6 @@ getName(); - $e = get_object_vars($element); - if (!empty($e)) { - $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; - } else { - $arr[$tag] = trim($element); - } - } - - return $arr; - } } From 379574ea25bae05aedd50a4c255a81a2db1860a8 Mon Sep 17 00:00:00 2001 From: Jon goldberg Date: Tue, 19 Dec 2017 18:53:05 -0500 Subject: [PATCH 13/35] Fix autoloader fatal errors from class reorganization --- src/AIMGateway.php | 2 +- src/Message/Query/AIMAbstractQueryRequest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AIMGateway.php b/src/AIMGateway.php index 8295d2bc..03fe16a6 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -179,7 +179,7 @@ public function paymentPlanQuery(array $parameters = array()) */ public function query(array $parameters = array()) { - return $this->createRequest('\Omnipay\AuthorizeNet\Message\QueryRequest', $parameters); + return $this->createRequest('\Omnipay\AuthorizeNet\Message\Query\QueryRequest', $parameters); } /** diff --git a/src/Message/Query/AIMAbstractQueryRequest.php b/src/Message/Query/AIMAbstractQueryRequest.php index 560dd006..9f719070 100644 --- a/src/Message/Query/AIMAbstractQueryRequest.php +++ b/src/Message/Query/AIMAbstractQueryRequest.php @@ -2,6 +2,8 @@ namespace Omnipay\AuthorizeNet\Message\Query; +use Omnipay\AuthorizeNet\Message\AIMAbstractRequest; + /** * Authorize.Net AIM Abstract Request */ From d091c9c8e15d7983c06d4832b917a9ddf4bc0c79 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 5 Jan 2018 15:57:28 -0500 Subject: [PATCH 14/35] Add capture only tests --- tests/AIMGatewayTest.php | 21 +++++++++++++++++++++ tests/Message/AIMResponseTest.php | 28 ++++++++++++++++++++++++++++ tests/Mock/AIMCaptureOnlyFailure.txt | 13 +++++++++++++ tests/Mock/AIMCaptureOnlySuccess.txt | 13 +++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 tests/Mock/AIMCaptureOnlyFailure.txt create mode 100644 tests/Mock/AIMCaptureOnlySuccess.txt diff --git a/tests/AIMGatewayTest.php b/tests/AIMGatewayTest.php index 827ccac0..2748b092 100644 --- a/tests/AIMGatewayTest.php +++ b/tests/AIMGatewayTest.php @@ -126,7 +126,28 @@ public function testCaptureFailure() $this->assertSame('{"approvalCode":"","transId":"0"}', $response->getTransactionReference()); $this->assertSame('The transaction cannot be found.', $response->getMessage()); } + + public function testCaptureOnlySuccess() + { + $this->setMockHttpResponse('AIMCaptureOnlySuccess.txt'); + + $response = $this->gateway->capture($this->captureOptions)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertSame('{"approvalCode":"ROHNFQ","transId":"2214480791"}', $response->getTransactionReference()); + $this->assertSame('This transaction has been approved.', $response->getMessage()); + } + public function testCaptureOnlyFailure() + { + $this->setMockHttpResponse('AIMCaptureOnlyFailure.txt'); + + $response = $this->gateway->capture($this->captureOptions)->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertSame('{"approvalCode":"","transId":"0"}', $response->getTransactionReference()); + $this->assertSame('This transaction has been declined.', $response->getMessage()); + } public function testPurchaseSuccess() { $this->setMockHttpResponse('AIMPurchaseSuccess.txt'); diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 275fdfd8..999eabf8 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -101,6 +101,34 @@ public function testCaptureFailure() $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); } + + public function testCaptureOnlySuccess() + { + $httpResponse = $this->getMockHttpResponse('AIMCaptureOnlySuccess.txt'); + $response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody()); + + $this->assertTrue($response->isSuccessful()); + $this->assertSame('{"approvalCode":"ROHNFQ","transId":"2214480791"}', $response->getTransactionReference()); + $this->assertSame('This transaction has been approved.', $response->getMessage()); + $this->assertSame(1, $response->getResultCode()); + $this->assertSame(1, $response->getReasonCode()); + $this->assertSame('ROHNFQ', $response->getAuthorizationCode()); + $this->assertSame('P', $response->getAVSCode()); + } + + public function testCaptureOnlyFailure() + { + $httpResponse = $this->getMockHttpResponse('AIMCaptureOnlyFailure.txt'); + $response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody()); + + $this->assertFalse($response->isSuccessful()); + $this->assertSame('{"approvalCode":"","transId":"0"}', $response->getTransactionReference()); + $this->assertSame('This transaction has been declined.', $response->getMessage()); + $this->assertSame(2, $response->getResultCode()); + $this->assertSame(2, $response->getReasonCode()); + $this->assertSame('', $response->getAuthorizationCode()); + $this->assertSame('P', $response->getAVSCode()); + } public function testPurchaseSuccess() { diff --git a/tests/Mock/AIMCaptureOnlyFailure.txt b/tests/Mock/AIMCaptureOnlyFailure.txt new file mode 100644 index 00000000..b58e6cab --- /dev/null +++ b/tests/Mock/AIMCaptureOnlyFailure.txt @@ -0,0 +1,13 @@ +HTTP/1.1 200 OK +Date: Sat, 02 Aug 2014 05:27:33 GMT +Server: Microsoft-IIS/6.0 +Access-Control-Allow-Origin: * +Access-Control-Allow-Methods: GET, POST, OPTIONS +Access-Control-Allow-Headers: x-requested-with, cache-control, content-type, origin, method +X-Powered-By: ASP.NET +X-AspNet-Version: 2.0.50727 +Cache-Control: private +Content-Type: text/xml; charset=utf-8 +Content-Length: 868 + +123456ErrorE00027The transaction was unsuccessful.2P02214480791492E8E689EBD28D07749848B7C1E49D3XXXX0015Mastercard2This transaction has been declined. diff --git a/tests/Mock/AIMCaptureOnlySuccess.txt b/tests/Mock/AIMCaptureOnlySuccess.txt new file mode 100644 index 00000000..79eaa0b0 --- /dev/null +++ b/tests/Mock/AIMCaptureOnlySuccess.txt @@ -0,0 +1,13 @@ +HTTP/1.1 200 OK +Date: Sat, 02 Aug 2014 05:24:31 GMT +Server: Microsoft-IIS/6.0 +Access-Control-Allow-Origin: * +Access-Control-Allow-Methods: GET, POST, OPTIONS +Access-Control-Allow-Headers: x-requested-with, cache-control, content-type, origin, method +X-Powered-By: ASP.NET +X-AspNet-Version: 2.0.50727 +Cache-Control: private +Content-Type: text/xml; charset=utf-8 +Content-Length: 852 + +123456OkI00001Successful.1ROHNFQP22144807912214480791492E8E689EBD28D07749848B7C1E49D3XXXX0015Mastercard1This transaction has been approved. From f5893290a196cb5e0655e3e624c393866f8e12d2 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 5 Jan 2018 15:58:28 -0500 Subject: [PATCH 15/35] Add capture only request --- src/Message/AIMAbstractRequest.php | 10 ++++++++++ src/Message/AIMCaptureOnlyRequest.php | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/Message/AIMCaptureOnlyRequest.php diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 2282e254..2be9656f 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -111,6 +111,16 @@ public function setSolutionId($value) return $this->setParameter('solutionId', $value); } + public function getAuthCode() + { + return $this->getParameter('authCode'); + } + + public function setAuthCode($value) + { + return $this->setParameter('authCode', $value); + } + /** * @return TransactionReference */ diff --git a/src/Message/AIMCaptureOnlyRequest.php b/src/Message/AIMCaptureOnlyRequest.php new file mode 100644 index 00000000..55260bcd --- /dev/null +++ b/src/Message/AIMCaptureOnlyRequest.php @@ -0,0 +1,25 @@ +validate('amount'); + + $data = $this->getBaseData(); + $data->transactionRequest->amount = $this->getAmount(); + $data->transactionRequest->authCode = $this->getAuthCode(); + $this->addTransactionSettings($data); + + return $data; + } +} From 0af67afdb8d7d5e5070c64e1b1a916cee150a0db Mon Sep 17 00:00:00 2001 From: Sam L Date: Sat, 6 Jan 2018 22:46:16 -0500 Subject: [PATCH 16/35] Update request based on discussion on issue-93 https://github.com/thephpleague/omnipay-authorizenet/issues/93#issuecomment-355780401 --- src/Message/AIMCaptureOnlyRequest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Message/AIMCaptureOnlyRequest.php b/src/Message/AIMCaptureOnlyRequest.php index 55260bcd..2777210c 100644 --- a/src/Message/AIMCaptureOnlyRequest.php +++ b/src/Message/AIMCaptureOnlyRequest.php @@ -7,18 +7,15 @@ /** * Authorize.Net AIM Capture Only Request */ -class AIMCaptureOnlyRequest extends AIMAbstractRequest +class AIMCaptureOnlyRequest extends AIMAuthorizeRequest { protected $action = 'captureOnlyTransaction'; public function getData() { - $this->validate('amount'); + $data = parent::getData(); - $data = $this->getBaseData(); - $data->transactionRequest->amount = $this->getAmount(); $data->transactionRequest->authCode = $this->getAuthCode(); - $this->addTransactionSettings($data); return $data; } From 5db0086a6b73c0907cd8a0a32e4e375f51ec8e45 Mon Sep 17 00:00:00 2001 From: Sam L Date: Sat, 6 Jan 2018 22:46:56 -0500 Subject: [PATCH 17/35] Update tests --- tests/AIMGatewayTest.php | 6 +++--- tests/Message/AIMResponseTest.php | 12 ++++++------ tests/Mock/AIMCaptureOnlyFailure.txt | 6 +++--- tests/Mock/AIMCaptureOnlySuccess.txt | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/AIMGatewayTest.php b/tests/AIMGatewayTest.php index 2748b092..7a6ce81c 100644 --- a/tests/AIMGatewayTest.php +++ b/tests/AIMGatewayTest.php @@ -134,7 +134,7 @@ public function testCaptureOnlySuccess() $response = $this->gateway->capture($this->captureOptions)->send(); $this->assertTrue($response->isSuccessful()); - $this->assertSame('{"approvalCode":"ROHNFQ","transId":"2214480791"}', $response->getTransactionReference()); + $this->assertSame('{"approvalCode":"ROHNFQ","transId":"40009379672"}', $response->getTransactionReference()); $this->assertSame('This transaction has been approved.', $response->getMessage()); } @@ -145,8 +145,8 @@ public function testCaptureOnlyFailure() $response = $this->gateway->capture($this->captureOptions)->send(); $this->assertFalse($response->isSuccessful()); - $this->assertSame('{"approvalCode":"","transId":"0"}', $response->getTransactionReference()); - $this->assertSame('This transaction has been declined.', $response->getMessage()); + $this->assertSame('{"approvalCode":"ROHNFQ","transId":"0"}', $response->getTransactionReference()); + $this->assertSame('A valid amount is required.', $response->getMessage()); } public function testPurchaseSuccess() { diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 999eabf8..82030376 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -108,7 +108,7 @@ public function testCaptureOnlySuccess() $response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); - $this->assertSame('{"approvalCode":"ROHNFQ","transId":"2214480791"}', $response->getTransactionReference()); + $this->assertSame('{"approvalCode":"ROHNFQ","transId":"40009379672"}', $response->getTransactionReference()); $this->assertSame('This transaction has been approved.', $response->getMessage()); $this->assertSame(1, $response->getResultCode()); $this->assertSame(1, $response->getReasonCode()); @@ -122,11 +122,11 @@ public function testCaptureOnlyFailure() $response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); - $this->assertSame('{"approvalCode":"","transId":"0"}', $response->getTransactionReference()); - $this->assertSame('This transaction has been declined.', $response->getMessage()); - $this->assertSame(2, $response->getResultCode()); - $this->assertSame(2, $response->getReasonCode()); - $this->assertSame('', $response->getAuthorizationCode()); + $this->assertSame('{"approvalCode":"ROHNFQ","transId":"0"}', $response->getTransactionReference()); + $this->assertSame('A valid amount is required.', $response->getMessage()); + $this->assertSame(3, $response->getResultCode()); + $this->assertSame(5, $response->getReasonCode()); + $this->assertSame('ROHNFQ', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); } diff --git a/tests/Mock/AIMCaptureOnlyFailure.txt b/tests/Mock/AIMCaptureOnlyFailure.txt index b58e6cab..f2dff42c 100644 --- a/tests/Mock/AIMCaptureOnlyFailure.txt +++ b/tests/Mock/AIMCaptureOnlyFailure.txt @@ -1,5 +1,5 @@ HTTP/1.1 200 OK -Date: Sat, 02 Aug 2014 05:27:33 GMT +Date: Sat, 02 Aug 2014 04:53:02 GMT Server: Microsoft-IIS/6.0 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, OPTIONS @@ -8,6 +8,6 @@ X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/xml; charset=utf-8 -Content-Length: 868 +Content-Length: 882 -123456ErrorE00027The transaction was unsuccessful.2P02214480791492E8E689EBD28D07749848B7C1E49D3XXXX0015Mastercard2This transaction has been declined. +123456ErrorE00027The transaction was unsuccessful.3ROHNFQP0680A8419B9B0C29DAA432BDFA73C3E830XXXX0015MasterCard5A valid amount is required. diff --git a/tests/Mock/AIMCaptureOnlySuccess.txt b/tests/Mock/AIMCaptureOnlySuccess.txt index 79eaa0b0..619a015c 100644 --- a/tests/Mock/AIMCaptureOnlySuccess.txt +++ b/tests/Mock/AIMCaptureOnlySuccess.txt @@ -8,6 +8,6 @@ X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/xml; charset=utf-8 -Content-Length: 852 +Content-Length: 877 -123456OkI00001Successful.1ROHNFQP22144807912214480791492E8E689EBD28D07749848B7C1E49D3XXXX0015Mastercard1This transaction has been approved. +123456OkI00001Successful.1ROHNFQP4000937967213BA777FBC314C49558C9BE4250CEA240XXXX0015MasterCard1This transaction has been approved. From cea163464a31bd0f0a40e4f836602a05235d178d Mon Sep 17 00:00:00 2001 From: Sam L Date: Sun, 7 Jan 2018 15:50:37 -0500 Subject: [PATCH 18/35] Update capture only request field order --- src/Message/AIMCaptureOnlyRequest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Message/AIMCaptureOnlyRequest.php b/src/Message/AIMCaptureOnlyRequest.php index 2777210c..f2868537 100644 --- a/src/Message/AIMCaptureOnlyRequest.php +++ b/src/Message/AIMCaptureOnlyRequest.php @@ -1,6 +1,6 @@ validate('amount'); + $data = $this->getBaseData(); + $data->transactionRequest->amount = $this->getAmount(); + $this->addPayment($data); $data->transactionRequest->authCode = $this->getAuthCode(); - + $this->addSolutionId($data); + $this->addBillingData($data); + $this->addCustomerIP($data); + $this->addTransactionSettings($data); + return $data; - } + } } From e755e26b2dc3e1d7983d50831289c1aea69361cf Mon Sep 17 00:00:00 2001 From: Sam L Date: Sun, 7 Jan 2018 15:51:24 -0500 Subject: [PATCH 19/35] Add capture only to aim gateway --- src/AIMGateway.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/AIMGateway.php b/src/AIMGateway.php index 03fe16a6..c4effed3 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -128,6 +128,15 @@ public function capture(array $parameters = array()) return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMCaptureRequest', $parameters); } + /** + * @param array $parameters + * @return AIMCaptureOnlyRequest + */ + public function captureOnly(array $parameters = array()) + { + return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMCaptureOnlyRequest', $parameters); + } + /** * @param array $parameters * @return AIMPurchaseRequest From 38a4c4fd272bff01feef22c29147ff027e26ba0d Mon Sep 17 00:00:00 2001 From: Sam L Date: Sun, 7 Jan 2018 16:50:31 -0500 Subject: [PATCH 20/35] Correct spacing --- src/Message/AIMCaptureOnlyRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AIMCaptureOnlyRequest.php b/src/Message/AIMCaptureOnlyRequest.php index f2868537..f6f6cbdb 100644 --- a/src/Message/AIMCaptureOnlyRequest.php +++ b/src/Message/AIMCaptureOnlyRequest.php @@ -24,5 +24,5 @@ public function getData() $this->addTransactionSettings($data); return $data; - } + } } From e7cefe226c1e171f282abbef989fea1db4c80303 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 12 Jan 2018 14:06:49 -0500 Subject: [PATCH 21/35] Add getCVVCode --- src/Message/AIMResponse.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 020b51d8..3da0e58c 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -139,7 +139,20 @@ public function getAVSCode() return ''; } } - + + /** + * Returns the Card Code Verfication return code. + * + * @return string A single character. Can be M, N, P, S, or U. + */ + public function getCVVCode() + { + if (isset($this->data->transactionResponse[0]->cvvResultCode)) { + return (string)$this->data->transactionResponse[0]->cvvResultCode; + } else { + return ''; + } + } /** * A composite key containing the gateway provided transaction reference as * well as other data points that may be required for subsequent transactions From 29d33aa4ef73862306e5b4ffa4b0dc2f03acd600 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 12 Jan 2018 14:06:57 -0500 Subject: [PATCH 22/35] Add tests for getCVVCode --- tests/Message/AIMResponseTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 82030376..33ed338f 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -34,6 +34,7 @@ public function testAuthorizeSuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('GA4OQP', $response->getAuthorizationCode()); $this->assertSame('Y', $response->getAVSCode()); + $this->assertSame('P', $response->getCVVCode()); } public function testAuthorizeFailure() @@ -48,6 +49,7 @@ public function testAuthorizeFailure() $this->assertSame(5, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testAuthorizeInvalid() @@ -62,6 +64,7 @@ public function testAuthorizeInvalid() $this->assertSame('E00007', $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testAuthorizeInvalidOTSToken() @@ -86,6 +89,7 @@ public function testCaptureSuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('F51OYG', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testCaptureFailure() @@ -100,6 +104,7 @@ public function testCaptureFailure() $this->assertSame(16, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testCaptureOnlySuccess() @@ -114,6 +119,7 @@ public function testCaptureOnlySuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('ROHNFQ', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testCaptureOnlyFailure() @@ -128,6 +134,7 @@ public function testCaptureOnlyFailure() $this->assertSame(5, $response->getReasonCode()); $this->assertSame('ROHNFQ', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testPurchaseSuccess() @@ -142,6 +149,7 @@ public function testPurchaseSuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('JE6JM1', $response->getAuthorizationCode()); $this->assertSame('Y', $response->getAVSCode()); + $this->assertSame('P', $response->getCVVCode()); } public function testPurchaseFailure() @@ -156,6 +164,7 @@ public function testPurchaseFailure() $this->assertSame(5, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testRefundSuccess() @@ -170,6 +179,7 @@ public function testRefundSuccess() $this->assertSame(1, $response->getResultCode()); $this->assertSame(1, $response->getReasonCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } public function testRefundFailure() @@ -184,5 +194,6 @@ public function testRefundFailure() $this->assertSame(54, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getCVVCode()); } } From ea732d10369bf386c1a350fff4637493f6d94404 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 12 Jan 2018 14:36:56 -0500 Subject: [PATCH 23/35] Add getAccountType --- src/Message/AIMResponse.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 020b51d8..57c10ded 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -177,4 +177,18 @@ public function getTransactionReference($serialize = true) return ''; } + + /** + * Returns the account type used for the transaction. + * + * @return string A multicharacter string. Can be Visa, MasterCard, Discover, AmericanExpress, DinersClub, JCB, or eCheck. + */ + public function getAccountType() + { + if (isset($this->data->transactionResponse[0]->accountType)) { + return (string)$this->data->transactionResponse[0]->accountType; + } else { + return ''; + } + } } From b1a1dda85ed819abb3f4aaa69bd590443f000ab2 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 12 Jan 2018 14:37:04 -0500 Subject: [PATCH 24/35] Add tests for getAccountType --- tests/Message/AIMResponseTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 82030376..00906b13 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -34,6 +34,7 @@ public function testAuthorizeSuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('GA4OQP', $response->getAuthorizationCode()); $this->assertSame('Y', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } public function testAuthorizeFailure() @@ -48,6 +49,7 @@ public function testAuthorizeFailure() $this->assertSame(5, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } public function testAuthorizeInvalid() @@ -86,6 +88,7 @@ public function testCaptureSuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('F51OYG', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } public function testCaptureFailure() @@ -100,6 +103,7 @@ public function testCaptureFailure() $this->assertSame(16, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('', $response->getAccountType()); } public function testCaptureOnlySuccess() @@ -114,6 +118,7 @@ public function testCaptureOnlySuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('ROHNFQ', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('MasterCard', $response->getAccountType()); } public function testCaptureOnlyFailure() @@ -128,6 +133,7 @@ public function testCaptureOnlyFailure() $this->assertSame(5, $response->getReasonCode()); $this->assertSame('ROHNFQ', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('MasterCard', $response->getAccountType()); } public function testPurchaseSuccess() @@ -142,6 +148,7 @@ public function testPurchaseSuccess() $this->assertSame(1, $response->getReasonCode()); $this->assertSame('JE6JM1', $response->getAuthorizationCode()); $this->assertSame('Y', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } public function testPurchaseFailure() @@ -156,6 +163,7 @@ public function testPurchaseFailure() $this->assertSame(5, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } public function testRefundSuccess() @@ -170,6 +178,7 @@ public function testRefundSuccess() $this->assertSame(1, $response->getResultCode()); $this->assertSame(1, $response->getReasonCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } public function testRefundFailure() @@ -184,5 +193,6 @@ public function testRefundFailure() $this->assertSame(54, $response->getReasonCode()); $this->assertSame('', $response->getAuthorizationCode()); $this->assertSame('P', $response->getAVSCode()); + $this->assertSame('Visa', $response->getAccountType()); } } From ecb76654de675b9b7aaf35fc82181e4b7c97e82f Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 12 Jan 2018 15:34:50 -0500 Subject: [PATCH 25/35] Reduce line length --- src/Message/AIMResponse.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 57c10ded..1216a96e 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -181,7 +181,8 @@ public function getTransactionReference($serialize = true) /** * Returns the account type used for the transaction. * - * @return string A multicharacter string. Can be Visa, MasterCard, Discover, AmericanExpress, DinersClub, JCB, or eCheck. + * @return string A multicharacter string. + * Can be Visa, MasterCard, Discover, AmericanExpress, DinersClub, JCB, or eCheck. */ public function getAccountType() { From ac570dadcc941a91f00afc9148a96f34cb7de53b Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 31 Jan 2018 22:40:47 +0000 Subject: [PATCH 26/35] Issue #105 fix. --- src/Message/AIMResponse.php | 40 ++++++++++---------- src/Message/CIMAbstractResponse.php | 14 ++++--- src/Message/CIMCreateCardResponse.php | 2 +- src/Message/CIMGetPaymentProfileResponse.php | 2 +- src/Message/CIMGetProfileResponse.php | 4 +- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 020b51d8..bd4ef670 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -59,8 +59,8 @@ public function isSuccessful() public function getResultCode() { // If there is a transaction response, then we get the code from that. - if (isset($this->data->transactionResponse[0])) { - return intval((string)$this->data->transactionResponse[0]->responseCode); + if (isset($this->data->transactionResponse)) { + return intval((string)$this->data->transactionResponse->responseCode); } // No transaction response, so return 3 aka "error". @@ -76,17 +76,17 @@ public function getReasonCode() { $code = null; - if (isset($this->data->transactionResponse[0]->messages)) { + if (isset($this->data->transactionResponse->messages)) { // In case of a successful transaction, a "messages" element is present - $code = intval((string)$this->data->transactionResponse[0]->messages[0]->message->code); + $code = intval((string)$this->data->transactionResponse->messages->message->code); - } elseif (isset($this->data->transactionResponse[0]->errors)) { + } elseif (isset($this->data->transactionResponse->errors)) { // In case of an unsuccessful transaction, an "errors" element is present - $code = intval((string)$this->data->transactionResponse[0]->errors[0]->error->errorCode); + $code = intval((string)$this->data->transactionResponse->errors->error->errorCode); - } elseif (isset($this->data->messages[0]->message)) { + } elseif (isset($this->data->messages->message)) { // In case of invalid request, the top-level message provides details. - $code = (string)$this->data->messages[0]->message->code; + $code = (string)$this->data->messages->message->code; } return $code; @@ -101,17 +101,17 @@ public function getMessage() { $message = null; - if (isset($this->data->transactionResponse[0]->messages)) { + if (isset($this->data->transactionResponse->messages)) { // In case of a successful transaction, a "messages" element is present - $message = (string)$this->data->transactionResponse[0]->messages[0]->message->description; + $message = (string)$this->data->transactionResponse->messages->message->description; - } elseif (isset($this->data->transactionResponse[0]->errors)) { + } elseif (isset($this->data->transactionResponse->errors)) { // In case of an unsuccessful transaction, an "errors" element is present - $message = (string)$this->data->transactionResponse[0]->errors[0]->error->errorText; + $message = (string)$this->data->transactionResponse->errors->error->errorText; - } elseif (isset($this->data->messages[0]->message)) { + } elseif (isset($this->data->messages->message)) { // In case of invalid request, the top-level message provides details. - $message = (string)$this->data->messages[0]->message->text; + $message = (string)$this->data->messages->message->text; } return $message; @@ -119,8 +119,8 @@ public function getMessage() public function getAuthorizationCode() { - if (isset($this->data->transactionResponse[0])) { - return (string)$this->data->transactionResponse[0]->authCode; + if (isset($this->data->transactionResponse)) { + return (string)$this->data->transactionResponse->authCode; } else { return ''; } @@ -133,8 +133,8 @@ public function getAuthorizationCode() */ public function getAVSCode() { - if (isset($this->data->transactionResponse[0])) { - return (string)$this->data->transactionResponse[0]->avsResultCode; + if (isset($this->data->transactionResponse)) { + return (string)$this->data->transactionResponse->avsResultCode; } else { return ''; } @@ -153,8 +153,8 @@ public function getTransactionReference($serialize = true) // The transactionResponse is only returned if succesful or declined // for some reason, so don't assume it will always be there. - if (isset($this->data->transactionResponse[0])) { - $body = $this->data->transactionResponse[0]; + if (isset($this->data->transactionResponse)) { + $body = $this->data->transactionResponse; $transactionRef = new TransactionReference(); $transactionRef->setApprovalCode((string)$body->authCode); $transactionRef->setTransId((string)$body->transId); diff --git a/src/Message/CIMAbstractResponse.php b/src/Message/CIMAbstractResponse.php index e02d7a7a..a2710d0a 100644 --- a/src/Message/CIMAbstractResponse.php +++ b/src/Message/CIMAbstractResponse.php @@ -27,10 +27,10 @@ public function __construct(RequestInterface $request, $data) // Check if this is an error response $isError = strpos((string)$data, 'responseType; + $xmlRootElement = ($isError !== false ? 'ErrorResponse' : $this->responseType); // Strip out the xmlns junk so that PHP can parse the XML $xml = preg_replace('/<' . $xmlRootElement . '[^>]+>/', '<' . $xmlRootElement . '>', (string)$data); - +//var_dump($xml); try { $xml = simplexml_load_string($xml); } catch (\Exception $e) { @@ -58,7 +58,7 @@ public function isSuccessful() */ public function getResultCode() { - $result = (string)$this->data['messages'][0]['resultCode']; + $result = (string)$this->data['messages']['resultCode']; switch ($result) { case 'Ok': @@ -82,7 +82,7 @@ public function getReasonCode() if (isset($this->data['messages'])) { // In case of a successful transaction, a "messages" element is present - $code = (string)$this->data['messages'][0]['message'][0]['code']; + $code = (string)$this->data['messages']['message']['code']; } return $code; @@ -114,7 +114,7 @@ public function getMessage() if (isset($this->data['messages'])) { // In case of a successful transaction, a "messages" element is present - $message = (string)$this->data['messages'][0]['message'][0]['text']; + $message = (string)$this->data['messages']['message']['text']; } @@ -155,13 +155,15 @@ public function getCardReference() */ public function xml2array(\SimpleXMLElement $xml) { + return json_decode(json_encode($xml), true); + $arr = array(); foreach ($xml as $element) { $tag = $element->getName(); $e = get_object_vars($element); - if (!empty($e)) { + if (! empty($e)) { $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e; } else { $arr[$tag] = trim($element); diff --git a/src/Message/CIMCreateCardResponse.php b/src/Message/CIMCreateCardResponse.php index 8139b4fd..aee6639f 100644 --- a/src/Message/CIMCreateCardResponse.php +++ b/src/Message/CIMCreateCardResponse.php @@ -20,7 +20,7 @@ public function getCustomerProfileId() public function getCustomerPaymentProfileId() { if ($this->isSuccessful()) { - return $this->data['customerPaymentProfileIdList'][0]['numericString']; + return $this->data['customerPaymentProfileIdList']['numericString']; } return null; } diff --git a/src/Message/CIMGetPaymentProfileResponse.php b/src/Message/CIMGetPaymentProfileResponse.php index f97f2292..2de602ba 100644 --- a/src/Message/CIMGetPaymentProfileResponse.php +++ b/src/Message/CIMGetPaymentProfileResponse.php @@ -12,7 +12,7 @@ class CIMGetPaymentProfileResponse extends CIMCreatePaymentProfileResponse public function getCustomerPaymentProfileId() { if ($this->isSuccessful()) { - return $this->data['paymentProfile'][0]['customerPaymentProfileId']; + return $this->data['paymentProfile']['customerPaymentProfileId']; } return null; } diff --git a/src/Message/CIMGetProfileResponse.php b/src/Message/CIMGetProfileResponse.php index 41fc503b..b7e03be8 100644 --- a/src/Message/CIMGetProfileResponse.php +++ b/src/Message/CIMGetProfileResponse.php @@ -26,9 +26,9 @@ public function getMatchingPaymentProfileId($last4) return null; } - foreach ($this->data['profile'][0]['paymentProfiles'] as $paymentProfile) { + foreach ($this->data['profile']['paymentProfiles'] as $paymentProfile) { // For every payment profile check if the last4 matches the last4 of the card in request. - $cardLast4 = substr($paymentProfile['payment'][0]['creditCard'][0]['cardNumber'], -4); + $cardLast4 = substr($paymentProfile['payment']['creditCard']['cardNumber'], -4); if ($last4 == $cardLast4) { return (string)$paymentProfile['customerPaymentProfileId']; } From 50a3bc2cd11ee49af03f158018342438fc45cdbb Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 31 Jan 2018 22:42:20 +0000 Subject: [PATCH 27/35] Introduce PHP7.2 tests --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a910d105..57d8c461 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - 5.6 - 7.0 - 7.1 - - hhvm + - 7.2 matrix: allow_failures: From 0064e7c40fc8cb7546dc12733a6f2b69b888398e Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 31 Jan 2018 22:47:29 +0000 Subject: [PATCH 28/35] Removed a var_dump that escaped. --- src/Message/CIMAbstractResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/CIMAbstractResponse.php b/src/Message/CIMAbstractResponse.php index a2710d0a..adfe6e1a 100644 --- a/src/Message/CIMAbstractResponse.php +++ b/src/Message/CIMAbstractResponse.php @@ -30,7 +30,7 @@ public function __construct(RequestInterface $request, $data) $xmlRootElement = ($isError !== false ? 'ErrorResponse' : $this->responseType); // Strip out the xmlns junk so that PHP can parse the XML $xml = preg_replace('/<' . $xmlRootElement . '[^>]+>/', '<' . $xmlRootElement . '>', (string)$data); -//var_dump($xml); + try { $xml = simplexml_load_string($xml); } catch (\Exception $e) { From 138fd4810b0526e2c9e5201dacd228a33d202d6c Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 17 May 2018 13:21:52 +0200 Subject: [PATCH 29/35] Update to v3 --- .travis.yml | 7 +------ composer.json | 6 +++--- phpunit.xml.dist | 3 --- src/Message/AIMAbstractRequest.php | 4 ++-- src/Message/CIMAbstractRequest.php | 4 ++-- src/Message/CIMCreateCardRequest.php | 4 ++-- src/Message/CIMCreatePaymentProfileRequest.php | 4 ++-- src/Message/CIMDeletePaymentProfileRequest.php | 4 ++-- src/Message/CIMGetPaymentProfileRequest.php | 4 ++-- src/Message/CIMGetProfileRequest.php | 4 ++-- src/Message/CIMUpdatePaymentProfileRequest.php | 4 ++-- src/Message/Query/AIMPaymentPlanQueryRequest.php | 4 ++-- src/Message/Query/AIMPaymentPlansQueryRequest.php | 4 ++-- src/Message/Query/QueryBatchDetailRequest.php | 4 ++-- src/Message/Query/QueryBatchRequest.php | 4 ++-- src/Message/Query/QueryDetailRequest.php | 4 ++-- src/Message/Query/QueryRequest.php | 4 ++-- src/Message/SIMAbstractRequest.php | 4 ++-- tests/CIMGatewayTest.php | 1 + tests/Message/AIMResponseTest.php | 3 ++- tests/Model/CardReferenceTest.php | 4 +++- tests/Model/TransactionReferenceTest.php | 4 +++- 22 files changed, 43 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index a910d105..5f827dc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,11 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 - - hhvm + - 7.2 -matrix: - allow_failures: - - php: hhvm before_script: - composer install -n --dev --prefer-source diff --git a/composer.json b/composer.json index 402d88fb..eaae87cf 100644 --- a/composer.json +++ b/composer.json @@ -28,14 +28,14 @@ "psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" } }, "require": { - "omnipay/common": "~2.2" + "omnipay/common": "^3" }, "require-dev": { - "omnipay/tests": "~2.0" + "omnipay/tests": "^3" }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a35b7362..535809e1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,9 +14,6 @@ ./tests/ - - - ./src diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 2be9656f..3608c581 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -224,9 +224,9 @@ public function sendData($data) $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new AIMResponse($this, $httpResponse->getBody()); + return $this->response = new AIMResponse($this, $httpResponse->getBody()->getContents()); } /** diff --git a/src/Message/CIMAbstractRequest.php b/src/Message/CIMAbstractRequest.php index 74d057bd..7e055c43 100644 --- a/src/Message/CIMAbstractRequest.php +++ b/src/Message/CIMAbstractRequest.php @@ -104,8 +104,8 @@ public function sendData($data) $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new CIMResponse($this, $httpResponse->getBody()); + return $this->response = new CIMResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index 81fa4b37..99313b66 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -152,9 +152,9 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - $response = new CIMCreateCardResponse($this, $httpResponse->getBody()); + $response = new CIMCreateCardResponse($this, $httpResponse->getBody()->getContents()); if (!$response->isSuccessful() && $response->getReasonCode() == 'E00039') { // Duplicate profile. Try adding a new payment profile for the same profile and get the response diff --git a/src/Message/CIMCreatePaymentProfileRequest.php b/src/Message/CIMCreatePaymentProfileRequest.php index 5948165b..f2c4ed92 100644 --- a/src/Message/CIMCreatePaymentProfileRequest.php +++ b/src/Message/CIMCreatePaymentProfileRequest.php @@ -43,8 +43,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new CIMCreatePaymentProfileResponse($this, $httpResponse->getBody()); + return $this->response = new CIMCreatePaymentProfileResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CIMDeletePaymentProfileRequest.php b/src/Message/CIMDeletePaymentProfileRequest.php index 4b30ac10..afb4c246 100644 --- a/src/Message/CIMDeletePaymentProfileRequest.php +++ b/src/Message/CIMDeletePaymentProfileRequest.php @@ -24,8 +24,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new CIMDeletePaymentProfileResponse($this, $httpResponse->getBody()); + return $this->response = new CIMDeletePaymentProfileResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CIMGetPaymentProfileRequest.php b/src/Message/CIMGetPaymentProfileRequest.php index a8da6cf6..2181fdc4 100644 --- a/src/Message/CIMGetPaymentProfileRequest.php +++ b/src/Message/CIMGetPaymentProfileRequest.php @@ -25,8 +25,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new CIMGetPaymentProfileResponse($this, $httpResponse->getBody()); + return $this->response = new CIMGetPaymentProfileResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CIMGetProfileRequest.php b/src/Message/CIMGetProfileRequest.php index 5f755475..caaea8e9 100644 --- a/src/Message/CIMGetProfileRequest.php +++ b/src/Message/CIMGetProfileRequest.php @@ -24,8 +24,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new CIMGetProfileResponse($this, $httpResponse->getBody()); + return $this->response = new CIMGetProfileResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/CIMUpdatePaymentProfileRequest.php b/src/Message/CIMUpdatePaymentProfileRequest.php index 37a7e1a9..4677adfb 100644 --- a/src/Message/CIMUpdatePaymentProfileRequest.php +++ b/src/Message/CIMUpdatePaymentProfileRequest.php @@ -44,8 +44,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new CIMUpdatePaymentProfileResponse($this, $httpResponse->getBody()); + return $this->response = new CIMUpdatePaymentProfileResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/Query/AIMPaymentPlanQueryRequest.php b/src/Message/Query/AIMPaymentPlanQueryRequest.php index d1a58a4b..244b4a73 100644 --- a/src/Message/Query/AIMPaymentPlanQueryRequest.php +++ b/src/Message/Query/AIMPaymentPlanQueryRequest.php @@ -47,8 +47,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new AIMPaymentPlanQueryResponse($this, $httpResponse->getBody()); + return $this->response = new AIMPaymentPlanQueryResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/Query/AIMPaymentPlansQueryRequest.php b/src/Message/Query/AIMPaymentPlansQueryRequest.php index 13afb190..77c4e6f1 100644 --- a/src/Message/Query/AIMPaymentPlansQueryRequest.php +++ b/src/Message/Query/AIMPaymentPlansQueryRequest.php @@ -46,8 +46,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new AIMPaymentPlansQueryResponse($this, $httpResponse->getBody()); + return $this->response = new AIMPaymentPlansQueryResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/Query/QueryBatchDetailRequest.php b/src/Message/Query/QueryBatchDetailRequest.php index 98d0d1c8..b390661c 100644 --- a/src/Message/Query/QueryBatchDetailRequest.php +++ b/src/Message/Query/QueryBatchDetailRequest.php @@ -29,9 +29,9 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new QueryBatchDetailResponse($this, $httpResponse->getBody()); + return $this->response = new QueryBatchDetailResponse($this, $httpResponse->getBody()->getContents()); } public function setBatchID($batchID) diff --git a/src/Message/Query/QueryBatchRequest.php b/src/Message/Query/QueryBatchRequest.php index 87f0fb3e..d9aa6684 100644 --- a/src/Message/Query/QueryBatchRequest.php +++ b/src/Message/Query/QueryBatchRequest.php @@ -16,8 +16,8 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new QueryBatchResponse($this, $httpResponse->getBody()); + return $this->response = new QueryBatchResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/Query/QueryDetailRequest.php b/src/Message/Query/QueryDetailRequest.php index 7b2034de..78283293 100644 --- a/src/Message/Query/QueryDetailRequest.php +++ b/src/Message/Query/QueryDetailRequest.php @@ -27,9 +27,9 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - return $this->response = new QueryDetailResponse($this, $httpResponse->getBody()); + return $this->response = new QueryDetailResponse($this, $httpResponse->getBody()->getContents()); } public function setTransactionReference($transactionReference) diff --git a/src/Message/Query/QueryRequest.php b/src/Message/Query/QueryRequest.php index 88118160..b7f0206d 100644 --- a/src/Message/Query/QueryRequest.php +++ b/src/Message/Query/QueryRequest.php @@ -65,9 +65,9 @@ public function sendData($data) { $headers = array('Content-Type' => 'text/xml; charset=utf-8'); $data = $data->saveXml(); - $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data); - $this->response = new QueryResponse($this, $httpResponse->getBody()); + $this->response = new QueryResponse($this, $httpResponse->getBody()->getContents()); return $this->response; } } diff --git a/src/Message/SIMAbstractRequest.php b/src/Message/SIMAbstractRequest.php index 4167e1fe..9bfd7b5a 100644 --- a/src/Message/SIMAbstractRequest.php +++ b/src/Message/SIMAbstractRequest.php @@ -160,9 +160,9 @@ protected function getBillingData() public function sendData($data) { - $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); + $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], http_build_query($data)); - return $this->response = new AIMResponse($this, $httpResponse->getBody()); + return $this->response = new AIMResponse($this, $httpResponse->getBody()->getContents()); } public function getEndpoint() diff --git a/tests/CIMGatewayTest.php b/tests/CIMGatewayTest.php index 604f4707..3d4a85dd 100644 --- a/tests/CIMGatewayTest.php +++ b/tests/CIMGatewayTest.php @@ -214,6 +214,7 @@ public function testPurchaseFailure() public function testRefundSuccess() { + $this->markTestSkipped(); // $this->setMockHttpResponse('CIMRefundSuccess.txt'); // // $response = $this->gateway->refund($this->refundOptions)->send(); diff --git a/tests/Message/AIMResponseTest.php b/tests/Message/AIMResponseTest.php index 5846bea0..3e046436 100644 --- a/tests/Message/AIMResponseTest.php +++ b/tests/Message/AIMResponseTest.php @@ -18,7 +18,8 @@ public function getMockRequest($className = '\Omnipay\AuthorizeNet\Message\AIMAb public function testConstructEmpty() { - $this->setExpectedException('\Omnipay\Common\Exception\InvalidResponseException'); + $this->expectException('\Omnipay\Common\Exception\InvalidResponseException'); + new AIMResponse($this->getMockRequest(), ''); } diff --git a/tests/Model/CardReferenceTest.php b/tests/Model/CardReferenceTest.php index d471d2a4..11cea148 100644 --- a/tests/Model/CardReferenceTest.php +++ b/tests/Model/CardReferenceTest.php @@ -2,7 +2,9 @@ namespace Omnipay\AuthorizeNet\Model; -class CardReferenceTest extends \PHPUnit_Framework_TestCase +use Omnipay\Tests\TestCase; + +class CardReferenceTest extends TestCase { private $data; /** @var CardReference */ diff --git a/tests/Model/TransactionReferenceTest.php b/tests/Model/TransactionReferenceTest.php index b0cf0c80..8c0be267 100644 --- a/tests/Model/TransactionReferenceTest.php +++ b/tests/Model/TransactionReferenceTest.php @@ -2,7 +2,9 @@ namespace Omnipay\AuthorizeNet\Model; -class TransactionReferenceTest extends \PHPUnit_Framework_TestCase +use Omnipay\Tests\TestCase; + +class TransactionReferenceTest extends TestCase { private $data; /** @var TransactionReference */ From 3aa8002400c360c6d6a08c00dfc5491c30b92c85 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 17 May 2018 13:25:31 +0200 Subject: [PATCH 30/35] Better travisci --- .travis.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f827dc9..741f61d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,26 @@ php: - 7.1 - 7.2 +# This triggers builds to run on the new TravisCI infrastructure. +# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ +sudo: false -before_script: - - composer install -n --dev --prefer-source +## Cache composer +cache: + directories: + - $HOME/.composer/cache + +env: + global: + - setup=basic + +matrix: + include: + - php: 5.6 + env: setup=lowest + +install: + - if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi + - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text From 0ffbd6c078208ee61e667618c32de0a7bfc13896 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 17 May 2018 13:28:10 +0200 Subject: [PATCH 31/35] Fix codestyle --- composer.json | 12 ++++++++++-- grumphp.yml | 15 +++++++++++++++ src/Message/AIMResponse.php | 4 ---- src/Message/CIMAbstractResponse.php | 2 -- src/Message/Query/QueryDetailResponse.php | 2 -- 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 grumphp.yml diff --git a/composer.json b/composer.json index eaae87cf..6ccff1e5 100644 --- a/composer.json +++ b/composer.json @@ -31,11 +31,19 @@ "omnipay/common": "^3" }, "require-dev": { - "omnipay/tests": "^3" + "omnipay/tests": "^3", + "squizlabs/php_codesniffer": "^3", + "phpro/grumphp": "^0.14" }, "extra": { "branch-alias": { "dev-master": "3.0.x-dev" } - } + }, + "scripts": { + "test": "phpunit", + "check-style": "phpcs -p --standard=PSR2 src/", + "fix-style": "phpcbf -p --standard=PSR2 src/" + }, + "prefer-stable": true } diff --git a/grumphp.yml b/grumphp.yml new file mode 100644 index 00000000..4b767a09 --- /dev/null +++ b/grumphp.yml @@ -0,0 +1,15 @@ +parameters: + git_dir: . + bin_dir: vendor/bin + tasks: + phpunit: + config_file: ~ + testsuite: ~ + group: [] + always_execute: false + phpcs: + standard: PSR2 + warning_severity: ~ + ignore_patterns: + - tests/ + triggered_by: [php] \ No newline at end of file diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index 6485d79b..7397dba4 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -79,11 +79,9 @@ public function getReasonCode() if (isset($this->data->transactionResponse[0]->messages)) { // In case of a successful transaction, a "messages" element is present $code = intval((string)$this->data->transactionResponse[0]->messages[0]->message->code); - } elseif (isset($this->data->transactionResponse[0]->errors)) { // In case of an unsuccessful transaction, an "errors" element is present $code = intval((string)$this->data->transactionResponse[0]->errors[0]->error->errorCode); - } elseif (isset($this->data->messages[0]->message)) { // In case of invalid request, the top-level message provides details. $code = (string)$this->data->messages[0]->message->code; @@ -104,11 +102,9 @@ public function getMessage() if (isset($this->data->transactionResponse[0]->messages)) { // In case of a successful transaction, a "messages" element is present $message = (string)$this->data->transactionResponse[0]->messages[0]->message->description; - } elseif (isset($this->data->transactionResponse[0]->errors)) { // In case of an unsuccessful transaction, an "errors" element is present $message = (string)$this->data->transactionResponse[0]->errors[0]->error->errorText; - } elseif (isset($this->data->messages[0]->message)) { // In case of invalid request, the top-level message provides details. $message = (string)$this->data->messages[0]->message->text; diff --git a/src/Message/CIMAbstractResponse.php b/src/Message/CIMAbstractResponse.php index e02d7a7a..db49d9e0 100644 --- a/src/Message/CIMAbstractResponse.php +++ b/src/Message/CIMAbstractResponse.php @@ -67,7 +67,6 @@ public function getResultCode() return static::TRANSACTION_RESULT_CODE_ERROR; default: return null; - } } @@ -115,7 +114,6 @@ public function getMessage() if (isset($this->data['messages'])) { // In case of a successful transaction, a "messages" element is present $message = (string)$this->data['messages'][0]['message'][0]['text']; - } return $message; diff --git a/src/Message/Query/QueryDetailResponse.php b/src/Message/Query/QueryDetailResponse.php index cb151f1e..359e896a 100644 --- a/src/Message/Query/QueryDetailResponse.php +++ b/src/Message/Query/QueryDetailResponse.php @@ -147,8 +147,6 @@ public function getCustomerReference() $this->planResponse = $gateway->paymentPlanQuery($data)->send(); } return $this->planResponse->getContactReference(); - - } /** From efe8ba9834e7a40eaa502ffeba239fae29c44c81 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 17 May 2018 13:50:45 +0200 Subject: [PATCH 32/35] Fix cs --- src/Message/AIMResponse.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Message/AIMResponse.php b/src/Message/AIMResponse.php index f40cd7f8..785b6c24 100644 --- a/src/Message/AIMResponse.php +++ b/src/Message/AIMResponse.php @@ -79,11 +79,9 @@ public function getReasonCode() if (isset($this->data->transactionResponse->messages)) { // In case of a successful transaction, a "messages" element is present $code = intval((string)$this->data->transactionResponse->messages->message->code); - } elseif (isset($this->data->transactionResponse->errors)) { // In case of an unsuccessful transaction, an "errors" element is present $code = intval((string)$this->data->transactionResponse->errors->error->errorCode); - } elseif (isset($this->data->messages->message)) { // In case of invalid request, the top-level message provides details. $code = (string)$this->data->messages->message->code; @@ -104,11 +102,9 @@ public function getMessage() if (isset($this->data->transactionResponse->messages)) { // In case of a successful transaction, a "messages" element is present $message = (string)$this->data->transactionResponse->messages->message->description; - } elseif (isset($this->data->transactionResponse->errors)) { // In case of an unsuccessful transaction, an "errors" element is present $message = (string)$this->data->transactionResponse->errors->error->errorText; - } elseif (isset($this->data->messages->message)) { // In case of invalid request, the top-level message provides details. $message = (string)$this->data->messages->message->text; From c8e03ff3996e8ecbac6ab3563bb588b066fe69bd Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 17 May 2018 14:53:10 +0200 Subject: [PATCH 33/35] Update README.md --- README.md | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index daad684c..1be68e11 100644 --- a/README.md +++ b/README.md @@ -11,21 +11,11 @@ processing library for PHP 5.3+. This package implements Authorize.Net support f ## Installation -Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it -to your `composer.json` file: - -```json -{ - "require": { - "omnipay/authorizenet": "~2.0" - } -} -``` - -And run composer to update your dependencies: +Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/authorizenet` with Composer: - $ curl -s http://getcomposer.org/installer | php - $ php composer.phar update +``` +composer require league/omnipay omnipay/authorizenet +``` ## Basic Usage From 04de992efa9a95632ccaa5f95d9c0f3f75b2545c Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 17 May 2018 14:53:23 +0200 Subject: [PATCH 34/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1be68e11..9c289280 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ processing library for PHP 5.3+. This package implements Authorize.Net support f Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/authorizenet` with Composer: ``` -composer require league/omnipay omnipay/authorizenet +composer require league/omnipay omnipay/authorizenet:"3.x@dev" ``` ## Basic Usage From 2e9d853dec005d94abf9c6643b238b55373b5fc8 Mon Sep 17 00:00:00 2001 From: Robert Purcell Date: Mon, 21 May 2018 13:33:06 -0400 Subject: [PATCH 35/35] CVV is optional --- src/Message/AIMAuthorizeRequest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index a4f0a58e..5b863feb 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -42,7 +42,9 @@ protected function addPayment(\SimpleXMLElement $data) $card->validate(); $data->transactionRequest->payment->creditCard->cardNumber = $card->getNumber(); $data->transactionRequest->payment->creditCard->expirationDate = $card->getExpiryDate('my'); - $data->transactionRequest->payment->creditCard->cardCode = $card->getCvv(); + if (!empty($card->getCvv())) { + $data->transactionRequest->payment->creditCard->cardCode = $card->getCvv(); + } } protected function addCustomerIP(\SimpleXMLElement $data)