Advertisement
Guest User

CakePHP & Nusoap Error

a guest
Oct 30th, 2012
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.35 KB | None | 0 0
  1. <?php
  2. ini_set('soap.wsdl_cache_enabled', 0);
  3.  
  4. class ServicesController extends AppController
  5. {
  6.     var $uses = array("Donation");
  7.     var $components = array( "Email", "MatchingEvents" );
  8.  
  9.     function registerDonation($donation = null){
  10.         $this->log('hit #1', 'donation');
  11.         $this->autoRender = false;
  12.         App::import('Vendor','nusoap');
  13.         Configure::write('debug',0);
  14.         Configure::write('Session.start', false);
  15.  
  16.         //init soap server
  17.         $server = new soap_server();
  18.        
  19.         $endpoint = 'http://new.mysite.org.uk/services/registerDonation';
  20.        
  21.         //initialize WSDL support
  22.         $server->configureWSDL('donations', 'urn:donations', $endpoint);
  23.  
  24.         //setup service type
  25.         $server->wsdl->addComplexType(
  26.             'DonationResult',
  27.             'complexType',
  28.             'struct',
  29.             'all',
  30.             '',
  31.             array(
  32.                 'success' => array('name' => 'success', 'type' => 'xsd:boolean'),
  33.                 'msg' => array('name' => 'msg', 'type' => 'xsd:string'),
  34.                 'error_number' => array('name' => 'error_number', 'type' => 'xsd:string')
  35.             )
  36.         );
  37.        
  38.         //register the method to expose
  39.         $server->register('register_donation',
  40.             array(
  41.                 'ct_number' => 'xsd:string',
  42.                 'project_id' => 'xsd:int',
  43.                 'donation_amount' => 'xsd:decimal',
  44.                 'gift_aid' => 'xsd:boolean',
  45.                 'donation_mode' => 'xsd:string',
  46.                 'donation_type' => 'xsd:string',
  47.                 'donor_title' => 'xsd:string',
  48.                 'donor_first_name' => 'xsd:string',
  49.                 'donor_last_name' => 'xsd:string',
  50.                 'donor_email' => 'xsd:string',
  51.                 'donor_address' => 'xsd:string',
  52.                 'donor_country' => 'xsd:string',
  53.                 'share_contact_with_charity' => 'xsd:string',
  54.                 'receive_updates' => 'xsd:string',
  55.                 'TransactionID' => 'xsd:string',
  56.                 'unique_ID' => 'xsd:string'
  57.             ),
  58.             array(
  59.                 'result' => 'tns:DonationResult'
  60.             ),
  61.             'urn:donations',
  62.             'urn:donations#register_donation',
  63.             'rpc',
  64.             'encoded',
  65.             'Accepts the results of a donation to a charity or project on the Big Give web site'
  66.         );
  67.         $this->log('hit #2 - register_donation is inside registerDonation', 'donation');
  68.        
  69.         //This inner function is registered and then called (keep within outer function!)
  70.         function register_donation(
  71.             $ct_number = null,
  72.             $project_id = null,
  73.             $donation_amount = null,
  74.             $gift_aid = null,
  75.             $donation_mode = null,
  76.             $donation_type = null,
  77.             $donor_title = null,
  78.             $donor_first_name = null,
  79.             $donor_last_name = null,
  80.             $donor_email = null,
  81.             $donor_address = null,
  82.             $donor_country = null,
  83.             $share_contact_with_charity = null,
  84.             $receive_updates = null,
  85.             $transaction_id = null,
  86.             $unique_id = null
  87.         ){
  88.             //App::import('Model', 'Donation');
  89.             //$Donation = new Donation();
  90.  
  91.             $this->log('hit #3-register_donation called!', 'donation');
  92.             $return = $this->Donation->add(array(
  93.                 'unique_id' => $unique_id,
  94.                 'ct_number' => $ct_number,
  95.                 'project_id' => $project_id,
  96.                 'donation_amount' => $donation_amount,
  97.                 'gift_aid' => $gift_aid,
  98.                 'donation_mode' => $donation_mode,
  99.                 'donation_type' => $donation_type,
  100.                 'donor_title' => $donor_title,
  101.                 'donor_first_name' => $donor_first_name,
  102.                 'donor_last_name' => $donor_last_name,
  103.                 'donor_email' => $donor_email,
  104.                 'donor_address' => $donor_address,
  105.                 'donor_country' => $donor_country,
  106.                 'share_contact_with_charity' => $share_contact_with_charity,
  107.                 'receive_updates' => $receive_updates,
  108.                 'transaction_id' => $transaction_id
  109.             ));
  110.            
  111.             $log = $this->Donation->log . 'Result: ' . $return['msg'] . "\n";
  112.             $this->log( $log, 'donation' );
  113.             if ( isset($this->Donation->matching['events']) )
  114.             {
  115.                 //Reserved donations should already have had their events handled
  116.                 $this->MatchingEvents->handle($this->Donation->matching, !$this->Donation->matching['reserved']);
  117.             }
  118.             if ( !empty($this->Donation->cacheSaved) )
  119.                 $this->_sendDonationEmails($this->Donation->cacheSaved);
  120.             return $return;
  121.         }
  122.        
  123.         $HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
  124.         $server->service($HTTP_RAW_POST_DATA);
  125.         $this->log('end','donation');
  126.     }
  127.  
  128.     function _sendDonationEmails($donation)
  129.     {
  130.         //Send our email...
  131.     }
  132.  
  133.     function testDonation($amount=1000, $unique_id=null, $ct_number=null, $charity_id=null, $project_id=null, $matched_campaign=null, $matched_cycle=null, $gift_aid='Y' )
  134.     {
  135.         // Simulates a test donation (Not via soap, but by inserting straight into db).
  136.     }
  137. }
  138.  
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement