r99825 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99824‎ | r99825 | r99826 >
Date:22:44, 14 October 2011
Author:kaldari
Status:ok
Tags:fundraising 
Comment:
making api testable with bogus data
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
@@ -10,14 +10,27 @@
1111
1212 $params = $this->extractRequestParams();
1313
14 - $gateway = $wgRequest->getText( 'gateway' );
 14+ // If you want to test with fake data, pass a 'test' param set to true.
 15+ // You still have to set the gateway you are testing though.
 16+ if ( array_key_exists( 'test', $params ) && $params['test'] ) {
 17+ $params = $this->getTestData();
 18+ }
1519
 20+ $gateway = $params['gateway'];
 21+ $method = $params['payment_method'];
 22+
1623 if ( $gateway == 'payflowpro' ) {
1724 $gatewayObj = new PayflowProAdapter();
18 - $result = $gatewayObj->do_transaction( 'Card' );
 25+ switch ( $method ) {
 26+ default:
 27+ $result = $gatewayObj->do_transaction( 'Card' );
 28+ }
1929 } else if ( $gateway == 'globalcollect' ) {
2030 $gatewayObj = new GlobalCollectAdapter();
21 - $result = $gatewayObj->do_transaction( 'TEST_CONNECTION' );
 31+ switch ( $method ) {
 32+ default:
 33+ $result = $gatewayObj->do_transaction( 'TEST_CONNECTION' );
 34+ }
2235 } else {
2336 $this->dieUsage( "Invalid gateway <<<$gateway>>> passed to Donation API.", 'unknown_gateway' );
2437 }
@@ -32,22 +45,23 @@
3346 public function getAllowedParams() {
3447 return array(
3548 'gateway' => $this->defineParam( 'gateway', true ),
36 - 'amount' => $this->defineParam( 'amount', true ),
37 - 'currency' => $this->defineParam( 'currency', true ),
38 - 'fname' => $this->defineParam( 'fname', true ),
 49+ 'amount' => $this->defineParam( 'amount', false ),
 50+ 'currency' => $this->defineParam( 'currency', false ),
 51+ 'fname' => $this->defineParam( 'fname', false ),
3952 'mname' => $this->defineParam( 'mname', false ),
40 - 'lname' => $this->defineParam( 'lname', true ),
41 - 'street' => $this->defineParam( 'street', true ),
42 - 'city' => $this->defineParam( 'city', true ),
43 - 'state' => $this->defineParam( 'state', true ),
44 - 'zip' => $this->defineParam( 'zip', true ),
45 - 'email' => $this->defineParam( 'email', true ),
46 - 'country' => $this->defineParam( 'country', true ),
 53+ 'lname' => $this->defineParam( 'lname', false ),
 54+ 'street' => $this->defineParam( 'street', false ),
 55+ 'city' => $this->defineParam( 'city', false ),
 56+ 'state' => $this->defineParam( 'state', false ),
 57+ 'zip' => $this->defineParam( 'zip', false ),
 58+ 'email' => $this->defineParam( 'email', false ),
 59+ 'country' => $this->defineParam( 'country', false ),
4760 'card_num' => $this->defineParam( 'card_num', false ),
4861 'card_type' => $this->defineParam( 'card_type', false ),
4962 'expiration' => $this->defineParam( 'expiration', false ),
5063 'cvv' => $this->defineParam( 'cvv', false ),
5164 'payment_method' => $this->defineParam( 'payment_method', false ),
 65+ 'language' => $this->defineParam( 'language', false ),
5266 );
5367 }
5468
@@ -59,12 +73,51 @@
6074 }
6175 return $param;
6276 }
 77+
 78+ private function getTestData() {
 79+ $params = array(
 80+ 'amount' => "35",
 81+ 'currency' => 'USD',
 82+ 'fname' => 'Tester',
 83+ 'mname' => 'T.',
 84+ 'lname' => 'Testington',
 85+ 'street' => '548 Market St.',
 86+ 'city' => 'San Francisco',
 87+ 'state' => 'CA',
 88+ 'zip' => '94104',
 89+ 'email' => 'test@example.com',
 90+ 'country' => 'US',
 91+ 'card_num' => '378282246310005',
 92+ 'card_type' => 'american',
 93+ 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
 94+ 'cvv' => '001',
 95+ 'payment_method' => 'card',
 96+ 'language' => 'en',
 97+ );
 98+ return $params;
 99+ }
63100
64101 public function getParamDescription() {
65102 return array(
66103 'gateway' => 'Which payment gateway to use - payflowpro, globalcollect, etc.',
 104+ 'test' => 'Set to true if you want to use bogus test data instead of supplying your own',
67105 'amount' => 'The amount donated',
68106 'currency' => 'Currency code',
 107+ 'fname' => 'First name',
 108+ 'mname' => 'Middle name',
 109+ 'lname' => 'Last name',
 110+ 'street' => 'First line of street address',
 111+ 'city' => 'City',
 112+ 'state' => 'State abbreviation',
 113+ 'zip' => 'Postal code',
 114+ 'email' => 'Email address',
 115+ 'country' => 'Country code',
 116+ 'card_num' => 'Credit card number',
 117+ 'card_type' => 'Credit card type',
 118+ 'expiration' => 'Expiration date',
 119+ 'cvv' => 'CVV security code',
 120+ 'payment_method' => 'Payment method to use',
 121+ 'language' => 'Language code',
69122 );
70123 }
71124

Follow-up revisions

RevisionCommit summaryAuthorDate
r99830follow-up to r99825, improving test functionskaldari23:29, 14 October 2011

Status & tagging log