function execute($language) { global $wgRequest, $wgOut, $wgContributionTrackingReturnToURLDefault; if (!preg_match('/^[a-z-]+$/', $language)) { $language = 'en'; } $this->lang = Language::factory($language); $this->setHeaders(); $wgOut->setPageTitle(''); $gateway = $wgRequest->getText('gateway'); if (!in_array($gateway, array('paypal', 'moneybookers'))) { $wgOut->showErrorPage('contrib-tracking-error', 'contrib-tracking-error-text'); return; } // Store the contribution data if ($wgRequest->getVal('contribution_tracking_id')) { $contribution_tracking_id = $wgRequest->getVal('contribution_tracking_id', 0); } else { $tracked_contribution = array('note' => $wgRequest->getVal('comment'), 'referrer' => $wgRequest->getVal('referrer'), 'anonymous' => $wgRequest->getCheck('comment-option', false) ? false : true, 'utm_source' => $wgRequest->getVal('utm_source'), 'utm_medium' => $wgRequest->getVal('utm_medium'), 'utm_campaign' => $wgRequest->getVal('utm_campaign'), 'optout' => $wgRequest->getCheck('email-opt', false) ? false : true, 'language' => $wgRequest->getVal('language'), 'owa_session' => $wgRequest->getVal('owa_session'), 'owa_ref' => $wgRequest->getVal('owa_ref', null)); $contribution_tracking_id = ContributionTrackingProcessor::saveNewContribution($tracked_contribution); } $params = array('gateway' => $gateway, 'tshirt' => $wgRequest->getVal('tshirt'), 'return' => $wgRequest->getText('returnto', "Donate-thanks/{$language}"), 'currency_code' => $wgRequest->getText('currency_code', 'USD'), 'fname' => $wgRequest->getText('fname', null), 'lname' => $wgRequest->getText('lname', null), 'email' => $wgRequest->getText('email', null), 'address1' => $wgRequest->getText('address1', null), 'city' => $wgRequest->getText('city', null), 'state' => $wgRequest->getText('state', null), 'zip' => $wgRequest->getText('zip', null), 'country' => $wgRequest->getText('country', null), 'address_override' => $wgRequest->getText('address_override', '0'), 'recurring_paypal' => $wgRequest->getText('recurring_paypal'), 'amount' => $wgRequest->getVal('amount'), 'amount_given' => $wgRequest->getVal('amountGiven'), 'contribution_tracking_id' => $contribution_tracking_id, 'language' => $language); if ($params['tshirt']) { $params['size'] = $wgRequest->getText('size'); $params['premium_language'] = $wgRequest->getText('premium_language'); } foreach ($params as $key => $value) { if ($value === "" || $value === null) { unset($params[$key]); } } $repost = ContributionTrackingProcessor::getRepostFields($params); #$wgOut->addWikiText( "{{2009/Donate-banner/$language}}" ); $wgOut->addHTML($this->msgWiki('contrib-tracking-submitting')); // Output the repost form $output = '<form method="post" name="contributiontracking" action="' . $repost['action'] . '">'; foreach ($repost['fields'] as $key => $value) { $output .= '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />'; } $output .= $this->msgWiki('contrib-tracking-redirect'); // Offer a button to post the form if the user has no Javascript support $output .= '<noscript>'; $output .= $this->msgWiki('contrib-tracking-continue'); $output .= '<input type="submit" value="' . $this->msg('contrib-tracking-button') . '" />'; $output .= '</noscript>'; $output .= '</form>'; $wgOut->addHTML($output); // Automatically post the form if the user has Javascript support $wgOut->addHTML('<script type="text/javascript">document.contributiontracking.submit();</script>'); }
/** * Assembles the data for the API to return. * @param integer $id The Contribution Tracking ID. * @param array $params Original (staged) request paramaters. */ function doReturn($id, $params) { // foreach ($params as $key=>$value){ // if ($value != ''){ // $this->getResult()->addValue(array('returns', 'parrot'), $key, $value); // } // } $params['contribution_tracking_id'] = $id; $repost = ContributionTrackingProcessor::getRepostFields($params); $this->getResult()->addValue(array('returns', 'action'), 'url', $repost['action']); foreach ($repost['fields'] as $key => $value) { $this->getResult()->addValue(array('returns', 'fields'), $key, $value); } }
/** * tests the getRepostFields function. * Assertions: * getRepostFields returns an array. * getRepostFields returns expected fields for a one-time paypal * donation. * getRepostFields returns expected fields for a one-time paypal * donation. * getRepostFields returns expected fields for a one-time paypal * donation. * getRepostFields returns translated fields (when they will be * displayed by the gateway) and return-to's for the specified language. * */ function testGetRepostFields() { //TODO: More here. $minimal = array('referrer' => 'phpunit_processor', 'gateway' => 'paypal', 'amount' => '8.80'); $returnTitle = Title::newFromText('Donate-thanks/en'); $expected = array('action' => 'https://www.paypal.com/cgi-bin/webscr', 'fields' => array('business' => '*****@*****.**', 'item_number' => 'DONATE', 'no_note' => 0, 'return' => wfExpandUrl($returnTitle->getFullUrl(), PROTO_HTTP), 'currency_code' => 'USD', 'cmd' => '_xclick', 'notify_url' => 'https://civicrm.wikimedia.org/fundcore_gateway/paypal', 'item_name' => 'One-time donation', 'amount' => '8.80', 'custom' => '')); $ret = ContributionTrackingProcessor::getRepostFields($minimal); $this->assertTrue(is_array($ret), "Returned value is not an array"); $this->assertEquals($ret, $expected, "Fields for reposting (Paypal, one-time) do not match expected fields"); //test paypal recurring $minimal['recurring_paypal'] = true; $expected['fields']['t3'] = 'M'; $expected['fields']['p3'] = '1'; $expected['fields']['srt'] = '12'; $expected['fields']['src'] = '1'; $expected['fields']['sra'] = '1'; $expected['fields']['cmd'] = '_xclick-subscriptions'; $expected['fields']['item_name'] = 'Recurring monthly donation'; $expected['fields']['a3'] = '8.80'; unset($expected['fields']['amount']); $ret = ContributionTrackingProcessor::getRepostFields($minimal); $this->assertEquals($ret, $expected, "Fields for reposting (Paypal, recurring) do not match expected fields"); //test moneybookers... just in case anybody cares anymore. unset($minimal['recurring_paypal']); $minimal['gateway'] = 'moneybookers'; $expected = array('action' => 'https://www.moneybookers.com/app/payment.pl', 'fields' => array('merchant_fields' => 'os0', 'pay_to_email' => '*****@*****.**', 'status_url' => 'https://civicrm.wikimedia.org/fundcore_gateway/moneybookers', 'language' => 'en', 'detail1_description' => 'One-time donation', 'detail1_text' => 'DONATE', 'currency' => 'USD', 'amount' => '8.80', 'custom' => '')); $ret = ContributionTrackingProcessor::getRepostFields($minimal); $this->assertEquals($ret, $expected, "Fields for reposting (moneybookers, one-time) do not match expected fields"); //test alternate language $minimal['gateway'] = 'paypal'; $minimal['language'] = 'ja'; //japanese. $returnTitle = Title::newFromText('Donate-thanks/ja'); $expected = array('action' => 'https://www.paypal.com/cgi-bin/webscr', 'fields' => array('business' => '*****@*****.**', 'item_number' => 'DONATE', 'no_note' => 0, 'return' => wfExpandUrl($returnTitle->getFullUrl(), PROTO_HTTP), 'currency_code' => 'USD', 'cmd' => '_xclick', 'notify_url' => 'https://civicrm.wikimedia.org/fundcore_gateway/paypal', 'item_name' => '1回だけ寄付', 'amount' => '8.80', 'custom' => '')); $ret = ContributionTrackingProcessor::getRepostFields($minimal); $this->assertEquals($ret, $expected, "Fields for reposting (paypal, one-time, language=ja) do not match expected fields"); //test T-shirtness $minimal['gateway'] = 'paypal'; $minimal['language'] = 'en'; $minimal['tshirt'] = true; $minimal['size'] = 'medium'; $minimal['premium_language'] = 'ja'; $returnTitle = Title::newFromText('Donate-thanks/en'); $expected = array('action' => 'https://www.paypal.com/cgi-bin/webscr', 'fields' => array('business' => '*****@*****.**', 'item_number' => 'DONATE', 'no_note' => 0, 'return' => wfExpandUrl($returnTitle->getFullUrl(), PROTO_HTTP), 'currency_code' => 'USD', 'cmd' => '_xclick', 'notify_url' => 'https://civicrm.wikimedia.org/fundcore_gateway/paypal', 'item_name' => 'One-time donation', 'amount' => '8.80', 'custom' => '', 'on0' => 'Shirt size', 'os0' => 'medium', 'on1' => 'Shirt language', 'os1' => 'ja', 'no_shipping' => 2)); $ret = ContributionTrackingProcessor::getRepostFields($minimal); $this->assertEquals($ret, $expected, "Fields for reposting (paypal, one-time, T-shirt) do not match expected fields"); }