Index: trunk/extensions/DonationInterface/gateway_common/donation.api.php |
— | — | @@ -5,33 +5,34 @@ |
6 | 6 | * Call with api.php?action=donate |
7 | 7 | */ |
8 | 8 | class DonationApi extends ApiBase { |
| 9 | + var $donationData, $gateway; |
9 | 10 | public function execute() { |
10 | 11 | global $wgRequest, $wgParser; |
11 | 12 | |
12 | | - $params = $this->extractRequestParams(); |
13 | | - $options = array(); |
| 13 | + $this->donationData = $this->extractRequestParams(); |
14 | 14 | |
15 | | - $gateway = $params['gateway']; |
| 15 | + $this->gateway = $this->donationData['gateway']; |
16 | 16 | |
17 | 17 | // If you want to test with fake data, pass a 'test' param set to true. |
18 | 18 | // You still have to set the gateway you are testing though. |
19 | 19 | // It looks like this only works if the Test global variable for that gateway is true. |
20 | | - if ( array_key_exists( 'test', $params ) && $params['test'] ) { |
21 | | - $params = $this->getTestData( $gateway ); |
22 | | - $options['testData'] = $params; |
| 20 | + if ( array_key_exists( 'test', $this->donationData ) && $this->donationData['test'] ) { |
| 21 | + $this->populateTestData(); |
| 22 | + } else { |
| 23 | + // If we need to do any local data munging do it here. |
23 | 24 | } |
24 | 25 | |
25 | | - $method = $params['payment_method']; |
| 26 | + $method = $this->donationData['payment_method']; |
26 | 27 | |
27 | | - if ( $gateway == 'payflowpro' ) { |
28 | | - $gatewayObj = new PayflowProAdapter( $options ); |
| 28 | + if ( $this->gateway == 'payflowpro' ) { |
| 29 | + $gatewayObj = new PayflowProAdapter(); |
29 | 30 | switch ( $method ) { |
30 | 31 | // TODO: add other payment methods |
31 | 32 | default: |
32 | 33 | $result = $gatewayObj->do_transaction( 'Card' ); |
33 | 34 | } |
34 | | - } else if ( $gateway == 'globalcollect' ) { |
35 | | - $gatewayObj = new GlobalCollectAdapter( $options ); |
| 35 | + } else if ( $this->gateway == 'globalcollect' ) { |
| 36 | + $gatewayObj = new GlobalCollectAdapter(); |
36 | 37 | switch ( $method ) { |
37 | 38 | // TODO: add other payment methods |
38 | 39 | case 'card': |
— | — | @@ -48,11 +49,20 @@ |
49 | 50 | $outputResult = array(); |
50 | 51 | $outputResult['message'] = $result['message']; |
51 | 52 | $outputResult['status'] = $result['status']; |
52 | | - $outputResult['returnurl'] = $result['data']['PAYMENT']['RETURNURL']; |
53 | | - $outputResult['errors'] = implode( '; ', $result['errors'] ); |
| 53 | + if ( array_key_exists( 'RETURNURL', $result['data']['PAYMENT'] ) ) { |
| 54 | + $outputResult['returnurl'] = $result['data']['PAYMENT']['RETURNURL']; |
| 55 | + } |
| 56 | + if ( array_key_exists( 'FORMACTION', $result['data'] ) ) { |
| 57 | + $outputResult['formaction'] = $result['data']['FORMACTION']; |
| 58 | + } |
| 59 | + if ( $result['errors'] ) { |
| 60 | + $outputResult['errors'] = $result['errors']; |
| 61 | + } |
54 | 62 | |
55 | | - $this->getResult()->addValue( 'data', 'request', $params ); |
56 | | - $this->getResult()->addValue( 'data', 'result', $outputResult ); |
| 63 | + if ( $this->donationData ) { |
| 64 | + $this->getResult()->addValue( null, 'request', $this->donationData ); |
| 65 | + } |
| 66 | + $this->getResult()->addValue( null, 'result', $outputResult ); |
57 | 67 | |
58 | 68 | /* |
59 | 69 | $this->getResult()->setIndexedTagName( $result, 'response' ); |
— | — | @@ -93,9 +103,9 @@ |
94 | 104 | return $param; |
95 | 105 | } |
96 | 106 | |
97 | | - private function getTestData( $gateway ) { |
98 | | - $params = array( |
99 | | - 'gateway' => $gateway, |
| 107 | + private function populateTestData() { |
| 108 | + $this->donationData = array( |
| 109 | + 'gateway' => $this->gateway, |
100 | 110 | 'amount' => "35", |
101 | 111 | 'currency' => 'USD', |
102 | 112 | 'fname' => 'Tester', |
— | — | @@ -109,7 +119,7 @@ |
110 | 120 | 'country' => 'US', |
111 | 121 | 'payment_method' => 'card', |
112 | 122 | 'language' => 'en', |
113 | | - 'card_type' => '1', // Is this valid for PayflowPro? |
| 123 | + 'card_type' => 'american', |
114 | 124 | ); |
115 | 125 | if ( $gateway != 'globalcollect' ) { |
116 | 126 | $params += array( |
— | — | @@ -118,7 +128,7 @@ |
119 | 129 | 'cvv' => '001', |
120 | 130 | ); |
121 | 131 | } |
122 | | - return $params; |
| 132 | + return true; |
123 | 133 | } |
124 | 134 | |
125 | 135 | public function getParamDescription() { |