Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js |
— | — | @@ -130,8 +130,49 @@ |
131 | 131 | |
132 | 132 | /* Submit the form */ |
133 | 133 | /* TODO: Replace this with AJAX request */ |
134 | | - document.donationForm.action = $( "input[name='action']" ).val(); |
135 | | - document.donationForm.submit(); |
| 134 | + var sendData = { |
| 135 | + 'action': 'donate', |
| 136 | + 'gateway': 'payflowpro', |
| 137 | + 'currency': 'USD', |
| 138 | + 'amount': $( "input[name='amount']" ).val(), |
| 139 | + 'fname': $( "input[name='fname']" ).val(), |
| 140 | + 'lname': $( "input[name='lname']" ).val(), |
| 141 | + 'street': $( "input[name='street']" ).val(), |
| 142 | + 'city': $( "input[name='city']" ).val(), |
| 143 | + 'state': $( "input[name='state']" ).val(), |
| 144 | + 'zip': $( "input[name='zip']" ).val(), |
| 145 | + 'emailAdd': $( "input[name='emailAdd']" ).val(), |
| 146 | + 'country': $( "input[name='country']" ).val(), |
| 147 | + 'payment_method': 'card', |
| 148 | + 'language': 'en', |
| 149 | + |
| 150 | + 'expiration': $( "input[name='expiration']" ).val(), |
| 151 | + 'card_num': $( "input[name='card_num']" ).val(), |
| 152 | + 'cvv': $( "input[name='cvv']" ).val(), |
| 153 | + 'card_type': '', |
| 154 | + |
| 155 | + 'format': 'json' |
| 156 | + }; |
| 157 | + |
| 158 | + $.ajax( { |
| 159 | + 'url': mw.util.wikiScript( 'api' ), |
| 160 | + 'data': sendData, |
| 161 | + 'dataType': 'json', |
| 162 | + 'type': 'GET', |
| 163 | + 'success': function( data ) { |
| 164 | + if ( data.result.errors ) { |
| 165 | + var errors = new Array(); |
| 166 | + for( var key in data.result.errors ){ |
| 167 | + errors.push( data.result.errors[key] ); |
| 168 | + } |
| 169 | + alert ( errors.join( '\r\n' ) ); |
| 170 | + } else { |
| 171 | + /* Load the thank you page */ |
| 172 | + } |
| 173 | + } |
| 174 | + } ); |
| 175 | + //document.donationForm.action = $( "input[name='action']" ).val(); |
| 176 | + //document.donationForm.submit(); |
136 | 177 | } |
137 | 178 | } |
138 | 179 | |
Index: branches/fundraising/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() { |