jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/366565 )

Change subject: Approve and Cancel payment
......................................................................


Approve and Cancel payment

Bug: T163952
Change-Id: I17545aeb79eef027b046dfab62b3df40763677d0
---
M PaymentProviders/Ingenico/IngenicoPaymentProvider.php
A PaymentProviders/Ingenico/Tests/Data/paymentApproved.response
A PaymentProviders/Ingenico/Tests/Data/paymentCanceled.response
M PaymentProviders/Ingenico/Tests/phpunit/IngenicoPaymentProviderTest.php
4 files changed, 128 insertions(+), 0 deletions(-)

Approvals:
  XenoRyet: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/PaymentProviders/Ingenico/IngenicoPaymentProvider.php 
b/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
index e30a10e..93bf06f 100644
--- a/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
+++ b/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
@@ -24,4 +24,16 @@
                $response = $this->api->makeApiCall($path, 'GET');
                return $response;
        }
+
+       public function approvePayment($paymentId, $params){
+               $path = "payments/$paymentId/approve";
+               $response = $this->api->makeApiCall($path, 'POST', $params);
+               return $response;
+       }
+
+       public function cancelPayment($paymentId){
+               $path = "payments/$paymentId/cancel";
+               $response = $this->api->makeApiCall($path, 'POST');
+               return $response;
+       }
 }
diff --git a/PaymentProviders/Ingenico/Tests/Data/paymentApproved.response 
b/PaymentProviders/Ingenico/Tests/Data/paymentApproved.response
new file mode 100644
index 0000000..ac311f9
--- /dev/null
+++ b/PaymentProviders/Ingenico/Tests/Data/paymentApproved.response
@@ -0,0 +1,42 @@
+HTTP/1.1 200 OK
+Date: Mon, 30 Jan 2017 17:58:02 GMT
+Server: Apache/2.4.16 (Unix) OpenSSL/1.0.1t
+X-Powered-By: Servlet/3.0 JSP/2.2
+Transfer-Encoding: chunked
+Content-Type: application/json
+
+{
+  "payment": {
+    "id": "000000850010000188180000200001",
+    "paymentOutput": {
+      "amountOfMoney": {
+        "amount": 2890,
+        "currencyCode": "EUR"
+      },
+      "references": {
+        "paymentReference": "0"
+      },
+      "paymentMethod": "card",
+      "cardPaymentMethodSpecificOutput": {
+        "paymentProductId": 1,
+        "authorisationCode": "123456",
+        "card": {
+          "cardNumber": "************7977",
+          "expiryDate": "1220"
+        },
+        "fraudResults": {
+          "avsResult": "0",
+          "cvvResult": "M",
+          "fraudServiceResult": "no-advice"
+        }
+      }
+    },
+    "status": "CAPTURE_REQUESTED",
+    "statusOutput": {
+      "isCancellable": false,
+      "statusCode": 800,
+      "statusCodeChangeDateTime": "20140627140735",
+      "isAuthorized": true
+    }
+  }
+}
\ No newline at end of file
diff --git a/PaymentProviders/Ingenico/Tests/Data/paymentCanceled.response 
b/PaymentProviders/Ingenico/Tests/Data/paymentCanceled.response
new file mode 100644
index 0000000..b64fe66
--- /dev/null
+++ b/PaymentProviders/Ingenico/Tests/Data/paymentCanceled.response
@@ -0,0 +1,45 @@
+HTTP/1.1 200 OK
+Date: Mon, 30 Jan 2017 17:58:02 GMT
+Server: Apache/2.4.16 (Unix) OpenSSL/1.0.1t
+X-Powered-By: Servlet/3.0 JSP/2.2
+Transfer-Encoding: chunked
+Content-Type: application/json
+
+{
+  "payment": {
+    "id": "000000850010000188180000200001",
+    "paymentOutput": {
+      "amountOfMoney": {
+        "amount": 2890,
+        "currencyCode": "EUR"
+      },
+      "references": {
+        "merchantReference": "merchantReference",
+        "paymentReference": "0"
+      },
+      "paymentMethod": "card",
+      "cardPaymentMethodSpecificOutput": {
+        "paymentProductId": 1,
+        "authorisationCode": "726747",
+        "card": {
+          "cardNumber": "************7977",
+          "expiryDate": "1220"
+        },
+        "fraudResults": {
+          "avsResult": "0",
+          "cvvResult": "0",
+          "fraudServiceResult": "no-advice"
+        }
+      }
+    },
+    "status": "CANCELLED",
+    "statusOutput": {
+      "isCancellable": false,
+      "statusCode": 99999,
+      "statusCodeChangeDateTime": "20150223153431"
+    }
+  },
+    "cardPaymentMethodSpecificOutput": {
+      "voidResponseId": "0"
+  }
+}
diff --git 
a/PaymentProviders/Ingenico/Tests/phpunit/IngenicoPaymentProviderTest.php 
b/PaymentProviders/Ingenico/Tests/phpunit/IngenicoPaymentProviderTest.php
index eaa54a6..19fb291 100644
--- a/PaymentProviders/Ingenico/Tests/phpunit/IngenicoPaymentProviderTest.php
+++ b/PaymentProviders/Ingenico/Tests/phpunit/IngenicoPaymentProviderTest.php
@@ -32,4 +32,33 @@
                $response = $this->provider->getPaymentStatus($paymentId);
                $this->assertEquals($paymentId, $response['id']);
        }
+
+       public function testApprovePayment(){
+               $paymentId = '000000850010000188180000200001';
+               $params = array(
+                       "directDebitPaymentMethodSpecificInput" => array(
+                               "dateCollect" => Date("Ymd"),
+                       ),
+               );
+               $this->setUpResponse(__DIR__ . 
'/../Data/paymentApproved.response', 200);
+               $this->curlWrapper->expects( $this->once() )
+                       ->method( 'execute' )->with(
+                               
$this->equalTo("https://api-sandbox.globalcollect.com/v1/1234/payments/$paymentId/approve";),
+                               $this->equalTo('POST')
+                       );
+               $response = $this->provider->approvePayment($paymentId, 
$params);
+               $this->assertEquals($paymentId, $response['payment']['id']);
+       }
+
+       public function testCancelPayment(){
+               $paymentId = '000000850010000188180000200001';
+               $this->setUpResponse(__DIR__ . 
'/../Data/paymentCanceled.response', 200);
+               $this->curlWrapper->expects( $this->once() )
+                       ->method( 'execute' )->with(
+                               
$this->equalTo("https://api-sandbox.globalcollect.com/v1/1234/payments/$paymentId/cancel";),
+                               $this->equalTo('POST')
+                       );
+               $response = $this->provider->cancelPayment($paymentId);
+               $this->assertEquals($paymentId, $response['payment']['id']);
+       }
 }
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/366565
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I17545aeb79eef027b046dfab62b3df40763677d0
Gerrit-PatchSet: 6
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Mepps <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to