jenkins-bot has submitted this change and it was merged.

Change subject: Add script to fake Adyen queue/IPN messages
......................................................................


Add script to fake Adyen queue/IPN messages

It's a pain to test Adyen end to end because you have to populate
the pending queue with fake donor details, and create fake IPN
messages with matching order IDs. This script creates fake data
to import with SmashPig utilities.

Change-Id: Ief64328dc4392edd1170c712c14bf6c92346417b
---
A PaymentProviders/Adyen/Tests/faker/README
A PaymentProviders/Adyen/Tests/faker/faker.py
A PaymentProviders/Adyen/Tests/faker/templates/auth.xml
A PaymentProviders/Adyen/Tests/faker/templates/capture.xml
A PaymentProviders/Adyen/Tests/faker/templates/ipnContainer.xml
A PaymentProviders/Adyen/Tests/faker/templates/pending.json
6 files changed, 144 insertions(+), 0 deletions(-)

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



diff --git a/PaymentProviders/Adyen/Tests/faker/README 
b/PaymentProviders/Adyen/Tests/faker/README
new file mode 100644
index 0000000..48c2ebb
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/faker/README
@@ -0,0 +1,30 @@
+Creates matching DonationInterface queue messages and IPN posts
+
+Usage: faker.py 10
+
+Will dump 3 files into the current working directory.
+
+adyen-XXXXX-auths.xml
+adyen-XXXXX-captures.xml
+adyen-XXXXX-pending.json
+
+They will contain 10 messages each, with the same set of randomly generated
+contribution tracking IDs, order IDs, and gateway transaction IDs.
+
+First import the pending queue messages using the SmashPig maintenance script:
+
+~/src/SmashPig$ php Maintenance/PopulateQueueFromDump.php --config-file 
config.php --queue pending adyen-12345-pending.json
+
+Then use the soap injector to simulate some IPN messages for the 
authorizations:
+~/src/SmashPig/Tests/SoapInjector$ ./soapinject.py localhost 
'/ipn/smashpig_http_handler.php?p=adyen/listener' ../../adyen-12345-auths.xml
+
+This should queue up some capture request jobs. Run them like this:
+
+~/src/SmashPig$ php Maintenance/StompJobRunner.php --config-file config.php 
--config-node adyen
+TODO: fake API endpoint
+
+Then inject some capture success messages
+~/src/SmashPig/Tests/SoapInjector$ ./soapinject.py localhost 
'/ipn/smashpig_http_handler.php?p=adyen/listener' ../../adyen-12345-captures.xml
+
+This should queue up jobs to record the successful captures. Execute the job
+runner again and it should move the donor information into the Civi queue.
diff --git a/PaymentProviders/Adyen/Tests/faker/faker.py 
b/PaymentProviders/Adyen/Tests/faker/faker.py
new file mode 100755
index 0000000..207e128
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/faker/faker.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+import re
+import sys 
+import random
+import os
+
+if len(sys.argv) > 1:
+    num = int(sys.argv[1]);
+else:
+    num = 5;
+
+templatedir = os.path.dirname(os.path.realpath(__file__)) + '/templates/'
+
+with open(templatedir + 'ipnContainer.xml', 'r') as myfile:
+    ipnContainer = myfile.read()
+
+with open(templatedir + 'auth.xml', 'r') as myfile:
+    auth = myfile.read()
+
+with open(templatedir + 'capture.xml', 'r') as myfile:
+    capture = myfile.read()
+
+with open(templatedir + 'pending.json', 'r') as myfile:
+    pending = myfile.read()
+
+auths = ''
+captures = ''
+pqueue = ''
+
+fileprefix = 'adyen-' + str(random.randint(10000,100000))
+
+for x in range(0, num):
+    ctid = str(random.randint(100000,1000000))
+    oid = ctid + '.' + str(random.randint(0,4))
+    authid = str(random.randint(100000000000,1000000000000))
+    captureid = str(random.randint(100000000000,1000000000000))
+    header = 'adyen-'  + oid
+    pqueue += pending.replace('[[CTID]]', ctid).replace('[[ORDERID]]', oid)
+    auths += auth.replace('[[ORDERID]]', oid).replace('[[AUTHID]]', authid)
+    captures += captures.replace('[[ORDERID]]', oid).replace('[[AUTHID]]', 
authid).replace('[[CAPTUREID]]', captureid)
+
+with open(fileprefix + '-auths.xml', 'w') as myfile:
+    myfile.write( ipnContainer.replace('[[ITEMS]]', auths ))
+
+with open(fileprefix + '-captures.xml', 'w') as myfile:
+    myfile.write( ipnContainer.replace('[[ITEMS]]', captures ))
+
+with open(fileprefix + '-pending.json', 'w') as myfile:
+    myfile.write( pqueue )
+
+print('Dumped {0} fake donations in your lap. Bon appétit!'.format(num))
diff --git a/PaymentProviders/Adyen/Tests/faker/templates/auth.xml 
b/PaymentProviders/Adyen/Tests/faker/templates/auth.xml
new file mode 100644
index 0000000..323bc0d
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/faker/templates/auth.xml
@@ -0,0 +1,30 @@
+                                       <NotificationRequestItem>
+                                               <additionalData>
+                                                       <entry>
+                                                               <key 
xsi:type="xsd:string">cvcResult</key>
+                                                               <value 
xsi:type="xsd:string">1 Matches</value>
+                                                       </entry>
+                                                       <entry>
+                                                               <key 
xsi:type="xsd:string">avsResult</key>
+                                                               <value 
xsi:type="xsd:string">1 Address matches, postal code doesn't</value>
+                                                       </entry>
+                                               </additionalData>
+                                               <amount>
+                                                       <currency 
xmlns="http://common.services.adyen.com";>USD</currency>
+                                                       <value 
xmlns="http://common.services.adyen.com";>1000</value>
+                                               </amount>
+                                               
<eventCode>AUTHORISATION</eventCode>
+                                               
<eventDate>2016-01-25T17:07:36.862+01:00</eventDate>
+                                               
<merchantAccountCode>WikimediaCOM</merchantAccountCode>
+                                               
<merchantReference>[[ORDERID]]</merchantReference>
+                                               <operations>
+                                                       <string>CANCEL</string>
+                                                       <string>CAPTURE</string>
+                                                       <string>REFUND</string>
+                                               </operations>
+                                               <originalReference 
xsi:nil="true"/>
+                                               
<paymentMethod>amex</paymentMethod>
+                                               
<pspReference>[[AUTHID]]</pspReference>
+                                               
<reason>27533:0003:6/2016</reason>
+                                               <success>true</success>
+                                       </NotificationRequestItem>
diff --git a/PaymentProviders/Adyen/Tests/faker/templates/capture.xml 
b/PaymentProviders/Adyen/Tests/faker/templates/capture.xml
new file mode 100644
index 0000000..b876d58
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/faker/templates/capture.xml
@@ -0,0 +1,17 @@
+          <NotificationRequestItem>
+            <additionalData xsi:nil="true"/>
+            <amount>
+              <currency xmlns="http://common.services.adyen.com";>USD</currency>
+              <value xmlns="http://common.services.adyen.com";>1000</value>
+            </amount>
+            <eventCode>CAPTURE</eventCode>
+            <eventDate>2015-12-11T20:30:03+01:00</eventDate>
+            <merchantAccountCode>WikimediaCOM</merchantAccountCode>
+            <merchantReference>[[ORDERID]]</merchantReference>
+            <operations xsi:nil="true"/>
+            <originalReference>[[AUTHID]]</originalReference>
+            <paymentMethod>amex</paymentMethod>
+            <pspReference>[[CAPTUREID]]</pspReference>
+            <reason/>
+            <success>true</success>
+          </NotificationRequestItem>
diff --git a/PaymentProviders/Adyen/Tests/faker/templates/ipnContainer.xml 
b/PaymentProviders/Adyen/Tests/faker/templates/ipnContainer.xml
new file mode 100644
index 0000000..7965aa6
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/faker/templates/ipnContainer.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" ?>
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+       <soap:Body>
+               <ns1:sendNotification 
xmlns:ns1="http://notification.services.adyen.com";>
+                       <ns1:notification>
+                               <live 
xmlns="http://notification.services.adyen.com";>false</live>
+                               <notificationItems 
xmlns="http://notification.services.adyen.com";>
+[[ITEMS]]
+                               </notificationItems>
+                       </ns1:notification>
+               </ns1:sendNotification>
+       </soap:Body>
+</soap:Envelope>
+
diff --git a/PaymentProviders/Adyen/Tests/faker/templates/pending.json 
b/PaymentProviders/Adyen/Tests/faker/templates/pending.json
new file mode 100644
index 0000000..9570c91
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/faker/templates/pending.json
@@ -0,0 +1 @@
+raw={"headers":{"expires":"0","source_host":"lakitu","correlation-id":"adyen-[[ORDERID]]","source_enqueued_time":"1458060070","destination":"\/queue\/pending","php-message-class":"SmashPig\\CrmLink\\Messages\\DonationInterfaceMessage","source_type":"payments","priority":"4","source_version":"unknown","source_run_id":"2027","message-id":"ID:lakitu-33375-[[AUTHID]]-2:5:-1:1:1","persistent":"true","source_name":"DonationInterface","gateway":"adyen","timestamp":"1458060070309"},"body":"{\"contribution_tracking_id\":\"[[CTID]]\",\"country\":\"US\",\"date\":1458060070,\"email\":\"test[[CTID]]@example.com\",\"fee\":\"0\",\"gateway_account\":\"WikimediaCOM\",\"gateway\":\"adyen\",\"gateway_txn_id\":false,\"language\":\"en\",\"payment_method\":\"cc\",\"payment_submethod\":\"visa\",\"referrer\":\"https:\\\/\\\/mediawiki.dev\\\/index.php\\\/Main_Page\",\"response\":false,\"user_ip\":\"127.0.0.1\",\"utm_source\":\"..cc\",\"city\":\"Columbus\",\"currency\":\"USD\",\"first_name\":\"Testy[[CTID]]\",\"gross\":\"10.00\",\"last_name\":\"Testerson[[CTID]]\",\"recurring\":\"\",\"risk_score\":10,\"state_province\":\"OH\",\"street_address\":\"123
 Fake 
St\",\"utm_campaign\":\"\",\"utm_medium\":\"\",\"postal_code\":\"12345\"}"}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ief64328dc4392edd1170c712c14bf6c92346417b
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to