r100096 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100095‎ | r100096 | r100097 >
Date:22:56, 17 October 2011
Author:kaldari
Status:deferred
Tags:fundraising 
Comment:
some minor improvements to the donate API
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
@@ -9,28 +9,34 @@
1010 global $wgRequest, $wgParser;
1111
1212 $params = $this->extractRequestParams();
 13+ $options = array();
1314
1415 $gateway = $params['gateway'];
1516
1617 // If you want to test with fake data, pass a 'test' param set to true.
1718 // You still have to set the gateway you are testing though.
 19+ // It looks like this only works if the Test global variable for that gateway is true.
1820 if ( array_key_exists( 'test', $params ) && $params['test'] ) {
1921 $params = $this->getTestData( $gateway );
 22+ $options['testData'] = $params;
2023 }
2124
2225 $method = $params['payment_method'];
2326
2427 if ( $gateway == 'payflowpro' ) {
25 - $gatewayObj = new PayflowProAdapter();
 28+ $gatewayObj = new PayflowProAdapter( $options );
2629 switch ( $method ) {
2730 // TODO: add other payment methods
2831 default:
2932 $result = $gatewayObj->do_transaction( 'Card' );
3033 }
3134 } else if ( $gateway == 'globalcollect' ) {
32 - $gatewayObj = new GlobalCollectAdapter();
 35+ $gatewayObj = new GlobalCollectAdapter( $options );
3336 switch ( $method ) {
3437 // TODO: add other payment methods
 38+ case 'card':
 39+ $result = $gatewayObj->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
 40+ break;
3541 default:
3642 $result = $gatewayObj->do_transaction( 'TEST_CONNECTION' );
3743 }
@@ -39,38 +45,46 @@
4046 }
4147
4248 //$normalizedData = $gatewayObj->getData();
 49+ $outputResult = array();
 50+ $outputResult['message'] = $result['message'];
 51+ $outputResult['status'] = $result['status'];
 52+ $outputResult['returnurl'] = $result['data']['PAYMENT']['RETURNURL'];
 53+ $outputResult['errors'] = implode( '; ', $result['errors'] );
4354
44 - // Some output
 55+ $this->getResult()->addValue( 'data', 'request', $params );
 56+ $this->getResult()->addValue( 'data', 'result', $outputResult );
 57+
 58+ /*
4559 $this->getResult()->setIndexedTagName( $result, 'response' );
46 - $this->getResult()->addValue( 'data', 'request', $params );
4760 $this->getResult()->addValue( 'data', 'result', $result );
 61+ */
4862 }
4963
5064 public function getAllowedParams() {
5165 return array(
52 - 'gateway' => $this->defineParam( 'gateway', true ),
53 - 'test' => $this->defineParam( 'test', false ),
54 - 'amount' => $this->defineParam( 'amount', false ),
55 - 'currency' => $this->defineParam( 'currency', false ),
56 - 'fname' => $this->defineParam( 'fname', false ),
57 - 'mname' => $this->defineParam( 'mname', false ),
58 - 'lname' => $this->defineParam( 'lname', false ),
59 - 'street' => $this->defineParam( 'street', false ),
60 - 'city' => $this->defineParam( 'city', false ),
61 - 'state' => $this->defineParam( 'state', false ),
62 - 'zip' => $this->defineParam( 'zip', false ),
63 - 'email' => $this->defineParam( 'email', false ),
64 - 'country' => $this->defineParam( 'country', false ),
65 - 'card_num' => $this->defineParam( 'card_num', false ),
66 - 'card_type' => $this->defineParam( 'card_type', false ),
67 - 'expiration' => $this->defineParam( 'expiration', false ),
68 - 'cvv' => $this->defineParam( 'cvv', false ),
69 - 'payment_method' => $this->defineParam( 'payment_method', false ),
70 - 'language' => $this->defineParam( 'language', false ),
 66+ 'gateway' => $this->defineParam( true ),
 67+ 'test' => $this->defineParam( false ),
 68+ 'amount' => $this->defineParam( false ),
 69+ 'currency' => $this->defineParam( false ),
 70+ 'fname' => $this->defineParam( false ),
 71+ 'mname' => $this->defineParam( false ),
 72+ 'lname' => $this->defineParam( false ),
 73+ 'street' => $this->defineParam( false ),
 74+ 'city' => $this->defineParam( false ),
 75+ 'state' => $this->defineParam( false ),
 76+ 'zip' => $this->defineParam( false ),
 77+ 'emailAdd' => $this->defineParam( false ),
 78+ 'country' => $this->defineParam( false ),
 79+ 'card_num' => $this->defineParam( false ),
 80+ 'card_type' => $this->defineParam( false ),
 81+ 'expiration' => $this->defineParam( false ),
 82+ 'cvv' => $this->defineParam( false ),
 83+ 'payment_method' => $this->defineParam( false ),
 84+ 'language' => $this->defineParam( false ),
7185 );
7286 }
7387
74 - private function defineParam( $paramName, $required = false, $type = 'string' ) {
 88+ private function defineParam( $required = false, $type = 'string' ) {
7589 if ( $required ) {
7690 $param = array( ApiBase::PARAM_TYPE => $type, ApiBase::PARAM_REQUIRED => true );
7791 } else {
@@ -91,15 +105,19 @@
92106 'city' => 'San Francisco',
93107 'state' => 'CA',
94108 'zip' => '94104',
95 - 'email' => 'test@example.com',
 109+ 'emailAdd' => 'test@example.com',
96110 'country' => 'US',
97 - 'card_num' => '378282246310005',
98 - 'card_type' => 'american',
99 - 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
100 - 'cvv' => '001',
101111 'payment_method' => 'card',
102112 'language' => 'en',
 113+ 'card_type' => '1', // Is this valid for PayflowPro?
103114 );
 115+ if ( $gateway != 'globalcollect' ) {
 116+ $params += array(
 117+ 'card_num' => '378282246310005',
 118+ 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
 119+ 'cvv' => '001',
 120+ );
 121+ }
104122 return $params;
105123 }
106124
@@ -116,7 +134,7 @@
117135 'city' => 'City',
118136 'state' => 'State abbreviation',
119137 'zip' => 'Postal code',
120 - 'email' => 'Email address',
 138+ 'emailAdd' => 'Email address',
121139 'country' => 'Country code',
122140 'card_num' => 'Credit card number',
123141 'card_type' => 'Credit card type',

Status & tagging log