http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100272

Revision: 100272
Author:   kaldari
Date:     2011-10-19 20:28:44 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
more AJAX and API goodness

Modified Paths:
--------------
    
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
    
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js

Modified: 
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
   2011-10-19 20:19:50 UTC (rev 100271)
+++ 
branches/fundraising/extensions/DonationInterface/gateway_common/donation.api.php
   2011-10-19 20:28:44 UTC (rev 100272)
@@ -5,33 +5,34 @@
  * Call with api.php?action=donate
  */
 class DonationApi extends ApiBase {
+       var $donationData, $gateway;
        public function execute() {
                global $wgRequest, $wgParser;
                
-               $params = $this->extractRequestParams();
-               $options = array();
+               $this->donationData = $this->extractRequestParams();
                
-               $gateway = $params['gateway'];
+               $this->gateway = $this->donationData['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.
                // It looks like this only works if the Test global variable 
for that gateway is true.
-               if ( array_key_exists( 'test', $params ) && $params['test'] ) {
-                       $params = $this->getTestData( $gateway );
-                       $options['testData'] = $params;
+               if ( array_key_exists( 'test', $this->donationData ) && 
$this->donationData['test'] ) {
+                       $this->populateTestData();
+               } else {
+                       // If we need to do any local data munging do it here.
                }
                
-               $method = $params['payment_method'];
+               $method = $this->donationData['payment_method'];
                
-               if ( $gateway == 'payflowpro' ) {
-                       $gatewayObj = new PayflowProAdapter( $options );
+               if ( $this->gateway == 'payflowpro' ) {
+                       $gatewayObj = new PayflowProAdapter();
                        switch ( $method ) {
                                // TODO: add other payment methods
                                default:
                                        $result = $gatewayObj->do_transaction( 
'Card' );
                        }
-               } else if ( $gateway == 'globalcollect' ) {
-                       $gatewayObj = new GlobalCollectAdapter( $options );
+               } else if ( $this->gateway == 'globalcollect' ) {
+                       $gatewayObj = new GlobalCollectAdapter();
                        switch ( $method ) {
                                // TODO: add other payment methods
                                case 'card':
@@ -48,11 +49,20 @@
                $outputResult = array();
                $outputResult['message'] = $result['message'];
                $outputResult['status'] = $result['status'];
-               $outputResult['returnurl'] = 
$result['data']['PAYMENT']['RETURNURL'];
-               $outputResult['errors'] = implode( '; ', $result['errors'] );
+               if ( array_key_exists( 'RETURNURL', $result['data']['PAYMENT'] 
) ) {
+                       $outputResult['returnurl'] = 
$result['data']['PAYMENT']['RETURNURL'];
+               }
+               if ( array_key_exists( 'FORMACTION', $result['data'] ) ) {
+                       $outputResult['formaction'] = 
$result['data']['FORMACTION'];
+               }
+               if ( $result['errors'] ) {
+                       $outputResult['errors'] = $result['errors'];
+               }
                
-               $this->getResult()->addValue( 'data', 'request', $params );
-               $this->getResult()->addValue( 'data', 'result', $outputResult );
+               if ( $this->donationData ) {
+                       $this->getResult()->addValue( null, 'request', 
$this->donationData );
+               }
+               $this->getResult()->addValue( null, 'result', $outputResult );
                
                /*
                $this->getResult()->setIndexedTagName( $result, 'response' );
@@ -93,9 +103,9 @@
                return $param;
        }
        
-       private function getTestData( $gateway ) {
-               $params = array(
-                       'gateway' => $gateway,
+       private function populateTestData() {
+               $this->donationData = array(
+                       'gateway' => $this->gateway,
                        'amount' => "35",
                        'currency' => 'USD',
                        'fname' => 'Tester',
@@ -109,7 +119,7 @@
                        'country' => 'US',
                        'payment_method' => 'card',
                        'language' => 'en',
-                       'card_type' => '1', // Is this valid for PayflowPro?
+                       'card_type' => 'american',
                );
                if ( $gateway != 'globalcollect' ) {
                        $params += array(
@@ -118,7 +128,7 @@
                                'cvv' => '001',
                        );
                }
-               return $params;
+               return true;
        }
 
        public function getParamDescription() {

Modified: 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
  2011-10-19 20:19:50 UTC (rev 100271)
+++ 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
  2011-10-19 20:28:44 UTC (rev 100272)
@@ -130,8 +130,49 @@
                        
                        /* Submit the form */
                        /* TODO: Replace this with AJAX request */
-                       document.donationForm.action = $( 
"input[name='action']" ).val();
-                       document.donationForm.submit();
+                       var sendData = {
+                               'action': 'donate',
+                               'gateway': 'payflowpro',
+                               'currency': 'USD',
+                               'amount': $( "input[name='amount']" ).val(),
+                               'fname': $( "input[name='fname']" ).val(),
+                               'lname': $( "input[name='lname']" ).val(),
+                               'street': $( "input[name='street']" ).val(),
+                               'city': $( "input[name='city']" ).val(),
+                               'state': $( "input[name='state']" ).val(),
+                               'zip': $( "input[name='zip']" ).val(),
+                               'emailAdd': $( "input[name='emailAdd']" ).val(),
+                               'country': $( "input[name='country']" ).val(),
+                               'payment_method': 'card',
+                               'language': 'en',
+                               
+                               'expiration': $( "input[name='expiration']" 
).val(),
+                               'card_num': $( "input[name='card_num']" ).val(),
+                               'cvv': $( "input[name='cvv']" ).val(),
+                               'card_type': '',
+                               
+                               'format': 'json'
+                       };
+       
+                       $.ajax( {
+                               'url': mw.util.wikiScript( 'api' ),
+                               'data': sendData,
+                               'dataType': 'json',
+                               'type': 'GET',
+                               'success': function( data ) {
+                                       if ( data.result.errors ) {
+                                               var errors = new Array();
+                                               for( var key in 
data.result.errors ){ 
+                                                       errors.push( 
data.result.errors[key] );
+                                               }
+                                               alert ( errors.join( '\r\n' ) );
+                                       } else {
+                                               /* Load the thank you page */
+                                       }
+                               }
+                       } );
+                       //document.donationForm.action = $( 
"input[name='action']" ).val();
+                       //document.donationForm.submit();
                }
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to