r100272 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100271‎ | r100272 | r100273 >
Date:20:28, 19 October 2011
Author:kaldari
Status:deferred
Tags:fundraising 
Comment:
more AJAX and API goodness
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
@@ -130,8 +130,49 @@
131131
132132 /* Submit the form */
133133 /* 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();
136177 }
137178 }
138179
Index: branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
@@ -5,33 +5,34 @@
66 * Call with api.php?action=donate
77 */
88 class DonationApi extends ApiBase {
 9+ var $donationData, $gateway;
910 public function execute() {
1011 global $wgRequest, $wgParser;
1112
12 - $params = $this->extractRequestParams();
13 - $options = array();
 13+ $this->donationData = $this->extractRequestParams();
1414
15 - $gateway = $params['gateway'];
 15+ $this->gateway = $this->donationData['gateway'];
1616
1717 // If you want to test with fake data, pass a 'test' param set to true.
1818 // You still have to set the gateway you are testing though.
1919 // 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.
2324 }
2425
25 - $method = $params['payment_method'];
 26+ $method = $this->donationData['payment_method'];
2627
27 - if ( $gateway == 'payflowpro' ) {
28 - $gatewayObj = new PayflowProAdapter( $options );
 28+ if ( $this->gateway == 'payflowpro' ) {
 29+ $gatewayObj = new PayflowProAdapter();
2930 switch ( $method ) {
3031 // TODO: add other payment methods
3132 default:
3233 $result = $gatewayObj->do_transaction( 'Card' );
3334 }
34 - } else if ( $gateway == 'globalcollect' ) {
35 - $gatewayObj = new GlobalCollectAdapter( $options );
 35+ } else if ( $this->gateway == 'globalcollect' ) {
 36+ $gatewayObj = new GlobalCollectAdapter();
3637 switch ( $method ) {
3738 // TODO: add other payment methods
3839 case 'card':
@@ -48,11 +49,20 @@
4950 $outputResult = array();
5051 $outputResult['message'] = $result['message'];
5152 $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+ }
5462
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 );
5767
5868 /*
5969 $this->getResult()->setIndexedTagName( $result, 'response' );
@@ -93,9 +103,9 @@
94104 return $param;
95105 }
96106
97 - private function getTestData( $gateway ) {
98 - $params = array(
99 - 'gateway' => $gateway,
 107+ private function populateTestData() {
 108+ $this->donationData = array(
 109+ 'gateway' => $this->gateway,
100110 'amount' => "35",
101111 'currency' => 'USD',
102112 'fname' => 'Tester',
@@ -109,7 +119,7 @@
110120 'country' => 'US',
111121 'payment_method' => 'card',
112122 'language' => 'en',
113 - 'card_type' => '1', // Is this valid for PayflowPro?
 123+ 'card_type' => 'american',
114124 );
115125 if ( $gateway != 'globalcollect' ) {
116126 $params += array(
@@ -118,7 +128,7 @@
119129 'cvv' => '001',
120130 );
121131 }
122 - return $params;
 132+ return true;
123133 }
124134
125135 public function getParamDescription() {

Status & tagging log