Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('soap.wsdl_cache_enabled', 0);
- class ServicesController extends AppController
- {
- var $uses = array("Donation");
- var $components = array( "Email", "MatchingEvents" );
- function registerDonation($donation = null){
- $this->log('hit #1', 'donation');
- $this->autoRender = false;
- App::import('Vendor','nusoap');
- Configure::write('debug',0);
- Configure::write('Session.start', false);
- //init soap server
- $server = new soap_server();
- $endpoint = 'http://new.mysite.org.uk/services/registerDonation';
- //initialize WSDL support
- $server->configureWSDL('donations', 'urn:donations', $endpoint);
- //setup service type
- $server->wsdl->addComplexType(
- 'DonationResult',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'success' => array('name' => 'success', 'type' => 'xsd:boolean'),
- 'msg' => array('name' => 'msg', 'type' => 'xsd:string'),
- 'error_number' => array('name' => 'error_number', 'type' => 'xsd:string')
- )
- );
- //register the method to expose
- $server->register('register_donation',
- array(
- 'ct_number' => 'xsd:string',
- 'project_id' => 'xsd:int',
- 'donation_amount' => 'xsd:decimal',
- 'gift_aid' => 'xsd:boolean',
- 'donation_mode' => 'xsd:string',
- 'donation_type' => 'xsd:string',
- 'donor_title' => 'xsd:string',
- 'donor_first_name' => 'xsd:string',
- 'donor_last_name' => 'xsd:string',
- 'donor_email' => 'xsd:string',
- 'donor_address' => 'xsd:string',
- 'donor_country' => 'xsd:string',
- 'share_contact_with_charity' => 'xsd:string',
- 'receive_updates' => 'xsd:string',
- 'TransactionID' => 'xsd:string',
- 'unique_ID' => 'xsd:string'
- ),
- array(
- 'result' => 'tns:DonationResult'
- ),
- 'urn:donations',
- 'urn:donations#register_donation',
- 'rpc',
- 'encoded',
- 'Accepts the results of a donation to a charity or project on the Big Give web site'
- );
- $this->log('hit #2 - register_donation is inside registerDonation', 'donation');
- //This inner function is registered and then called (keep within outer function!)
- function register_donation(
- $ct_number = null,
- $project_id = null,
- $donation_amount = null,
- $gift_aid = null,
- $donation_mode = null,
- $donation_type = null,
- $donor_title = null,
- $donor_first_name = null,
- $donor_last_name = null,
- $donor_email = null,
- $donor_address = null,
- $donor_country = null,
- $share_contact_with_charity = null,
- $receive_updates = null,
- $transaction_id = null,
- $unique_id = null
- ){
- //App::import('Model', 'Donation');
- //$Donation = new Donation();
- $this->log('hit #3-register_donation called!', 'donation');
- $return = $this->Donation->add(array(
- 'unique_id' => $unique_id,
- 'ct_number' => $ct_number,
- 'project_id' => $project_id,
- 'donation_amount' => $donation_amount,
- 'gift_aid' => $gift_aid,
- 'donation_mode' => $donation_mode,
- 'donation_type' => $donation_type,
- 'donor_title' => $donor_title,
- 'donor_first_name' => $donor_first_name,
- 'donor_last_name' => $donor_last_name,
- 'donor_email' => $donor_email,
- 'donor_address' => $donor_address,
- 'donor_country' => $donor_country,
- 'share_contact_with_charity' => $share_contact_with_charity,
- 'receive_updates' => $receive_updates,
- 'transaction_id' => $transaction_id
- ));
- $log = $this->Donation->log . 'Result: ' . $return['msg'] . "\n";
- $this->log( $log, 'donation' );
- if ( isset($this->Donation->matching['events']) )
- {
- //Reserved donations should already have had their events handled
- $this->MatchingEvents->handle($this->Donation->matching, !$this->Donation->matching['reserved']);
- }
- if ( !empty($this->Donation->cacheSaved) )
- $this->_sendDonationEmails($this->Donation->cacheSaved);
- return $return;
- }
- $HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
- $server->service($HTTP_RAW_POST_DATA);
- $this->log('end','donation');
- }
- function _sendDonationEmails($donation)
- {
- //Send our email...
- }
- 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' )
- {
- // Simulates a test donation (Not via soap, but by inserting straight into db).
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement