http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99825
Revision: 99825
Author: kaldari
Date: 2011-10-14 22:44:52 +0000 (Fri, 14 Oct 2011)
Log Message:
-----------
making api testable with bogus data
Modified Paths:
--------------
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
Modified:
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
===================================================================
---
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
2011-10-14 22:17:56 UTC (rev 99824)
+++
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
2011-10-14 22:44:52 UTC (rev 99825)
@@ -10,14 +10,27 @@
$params = $this->extractRequestParams();
- $gateway = $wgRequest->getText( 'gateway' );
+ // If you want to test with fake data, pass a 'test' param set
to true.
+ // You still have to set the gateway you are testing though.
+ if ( array_key_exists( 'test', $params ) && $params['test'] ) {
+ $params = $this->getTestData();
+ }
+ $gateway = $params['gateway'];
+ $method = $params['payment_method'];
+
if ( $gateway == 'payflowpro' ) {
$gatewayObj = new PayflowProAdapter();
- $result = $gatewayObj->do_transaction( 'Card' );
+ switch ( $method ) {
+ default:
+ $result = $gatewayObj->do_transaction(
'Card' );
+ }
} else if ( $gateway == 'globalcollect' ) {
$gatewayObj = new GlobalCollectAdapter();
- $result = $gatewayObj->do_transaction(
'TEST_CONNECTION' );
+ switch ( $method ) {
+ default:
+ $result = $gatewayObj->do_transaction(
'TEST_CONNECTION' );
+ }
} else {
$this->dieUsage( "Invalid gateway <<<$gateway>>> passed
to Donation API.", 'unknown_gateway' );
}
@@ -32,22 +45,23 @@
public function getAllowedParams() {
return array(
'gateway' => $this->defineParam( 'gateway', true ),
- 'amount' => $this->defineParam( 'amount', true ),
- 'currency' => $this->defineParam( 'currency', true ),
- 'fname' => $this->defineParam( 'fname', true ),
+ 'amount' => $this->defineParam( 'amount', false ),
+ 'currency' => $this->defineParam( 'currency', false ),
+ 'fname' => $this->defineParam( 'fname', false ),
'mname' => $this->defineParam( 'mname', false ),
- 'lname' => $this->defineParam( 'lname', true ),
- 'street' => $this->defineParam( 'street', true ),
- 'city' => $this->defineParam( 'city', true ),
- 'state' => $this->defineParam( 'state', true ),
- 'zip' => $this->defineParam( 'zip', true ),
- 'email' => $this->defineParam( 'email', true ),
- 'country' => $this->defineParam( 'country', true ),
+ 'lname' => $this->defineParam( 'lname', false ),
+ 'street' => $this->defineParam( 'street', false ),
+ 'city' => $this->defineParam( 'city', false ),
+ 'state' => $this->defineParam( 'state', false ),
+ 'zip' => $this->defineParam( 'zip', false ),
+ 'email' => $this->defineParam( 'email', false ),
+ 'country' => $this->defineParam( 'country', false ),
'card_num' => $this->defineParam( 'card_num', false ),
'card_type' => $this->defineParam( 'card_type', false
),
'expiration' => $this->defineParam( 'expiration', false
),
'cvv' => $this->defineParam( 'cvv', false ),
'payment_method' => $this->defineParam(
'payment_method', false ),
+ 'language' => $this->defineParam( 'language', false ),
);
}
@@ -59,12 +73,51 @@
}
return $param;
}
+
+ private function getTestData() {
+ $params = array(
+ 'amount' => "35",
+ 'currency' => 'USD',
+ 'fname' => 'Tester',
+ 'mname' => 'T.',
+ 'lname' => 'Testington',
+ 'street' => '548 Market St.',
+ 'city' => 'San Francisco',
+ 'state' => 'CA',
+ 'zip' => '94104',
+ 'email' => '[email protected]',
+ 'country' => 'US',
+ 'card_num' => '378282246310005',
+ 'card_type' => 'american',
+ 'expiration' => date( 'my', strtotime( '+1 year 1
month' ) ),
+ 'cvv' => '001',
+ 'payment_method' => 'card',
+ 'language' => 'en',
+ );
+ return $params;
+ }
public function getParamDescription() {
return array(
'gateway' => 'Which payment gateway to use -
payflowpro, globalcollect, etc.',
+ 'test' => 'Set to true if you want to use bogus test
data instead of supplying your own',
'amount' => 'The amount donated',
'currency' => 'Currency code',
+ 'fname' => 'First name',
+ 'mname' => 'Middle name',
+ 'lname' => 'Last name',
+ 'street' => 'First line of street address',
+ 'city' => 'City',
+ 'state' => 'State abbreviation',
+ 'zip' => 'Postal code',
+ 'email' => 'Email address',
+ 'country' => 'Country code',
+ 'card_num' => 'Credit card number',
+ 'card_type' => 'Credit card type',
+ 'expiration' => 'Expiration date',
+ 'cvv' => 'CVV security code',
+ 'payment_method' => 'Payment method to use',
+ 'language' => 'Language code',
);
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs