| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 define('SIMPLE_PAYPAL_URL_LIVE', 0); 4 define('SIMPLE_PAYPAL_URL_TEST', 1); 5 6 define('SIMPLE_PAYPAL_URL', 'simple_paypal_url'); 7 define('SIMPLE_PAYPAL_DEFAULT_CURRENCY', 'simple_paypal_default_currency'); 8 9 function simple_paypal_get_urls() { 10 return array( 11 SIMPLE_PAYPAL_URL_LIVE => 'https://www.paypal.com/cgi-bin/webscr', 12 SIMPLE_PAYPAL_URL_TEST => 'https://www.sandbox.paypal.com/cgi-bin/webscr', 13 ); 14 } 15 16 /** 17 * Implementation of hook_menu(). 18 */ 19 function simple_paypal_menu() { 20 $items = array(); 21 22 $items['admin/settings/paypal'] = array( 23 'title' => 'Paypal', 24 'page callback' => 'drupal_get_form', 25 'page arguments' => array('simple_paypal_admin'), 26 'description' => 'Administer Paypal', 27 'access arguments' => array('access administration pages'), 28 'type' => MENU_NORMAL_ITEM, 29 ); 30 31 return $items; 32 } 33 34 /** 35 * Implementation of hook_admin(). 36 */ 37 function simple_paypal_admin() { 38 $form[SIMPLE_PAYPAL_URL] = array( 39 '#type' => 'select', 40 '#title' => t('Payment URL for Paypal'), 41 '#default_value' => variable_get(SIMPLE_PAYPAL_URL, SIMPLE_PAYPAL_URL_LIVE), 42 '#options' => simple_paypal_get_urls(), 43 '#description' => t('Select whether you want to use a live URL, or a test one.'), 44 ); 45 $form[SIMPLE_PAYPAL_DEFAULT_CURRENCY] = array( 46 '#type' => 'select', 47 '#title' => t('Default Currency'), 48 '#default_value' => variable_get(SIMPLE_PAYPAL_DEFAULT_CURRENCY, 'USD'), 49 '#options' => simple_paypal_get_currencies(), 50 ); 51 return system_settings_form($form); 52 } 53 54 function simple_paypal_get_url() { 55 $urls = simple_paypal_get_urls(); 56 return $urls[variable_get(SIMPLE_PAYPAL_URL, SIMPLE_PAYPAL_URL_LIVE)]; 57 } 58 59 function simple_paypal_get_currencies() { 60 $default_currency = variable_get(SIMPLE_PAYPAL_DEFAULT_CURRENCY, 'USD'); 61 $country_currencies = array( 62 'AUD' => t('Australian Dollar'), 63 'GBP' => t('British Pound'), 64 'CAD' => t('Canadian Dollar'), 65 'CZK' => t('Czech Koruna'), 66 'DKK' => t('Danish Kroner'), 67 'EUR' => t('Euro'), 68 'HKD' => t('Hong Kong Dollar'), 69 'HUF' => t('Hungarian Forint'), 70 'ILS' => t('Israeli New Shekel'), 71 'JPY' => t('Japanese Yen'), 72 'MXN' => t('Mexican Peso'), 73 'NZD' => t('New Zealand Dollar'), 74 'NOK' => t('Norwegian Kroner'), 75 'PLN' => t('Polish Zlotych'), 76 'SGD' => t('Singapore Dollar'), 77 'SEK' => t('Swedish Kronor'), 78 'CHF' => t('Swiss Franc'), 79 'USD' => t('U.S. Dollar'), 80 ); 81 82 if (variable_get(SIMPLE_PAYPAL_DEFAULT_CURRENCY, 'USD')) { 83 $ordered_currencies[$default_currency] = $country_currencies[$default_currency]; 84 foreach ($country_currencies as $key => $value) { 85 if($key != $default_currency) { 86 $ordered_currencies[$key] = $value; 87 } 88 } 89 return $ordered_currencies; 90 } 91 return $country_currencies; 92 } 93 94 function simple_paypal_format_amount($amount, $currency) { 95 $amount = number_format($amount, 2); 96 switch ($currency) { 97 case 'EUR': 98 return "€ $amount"; 99 case 'GBP': 100 return "£ $amount"; 101 case 'USD': 102 return "$ $amount"; 103 default: 104 return check_plain($currency). " $amount"; 105 } 106 } 107 108 function simple_paypal_ipn_verify($vars = array()) { 109 // If we are in test mode, log the variables. 110 if (SIMPLE_PAYPAL_URL_TEST == variable_get(SIMPLE_PAYPAL_URL, SIMPLE_PAYPAL_URL_TEST)) { 111 watchdog('simple_paypal', 'Post variables from Paypal IPN <pre>@vars</pre>', array( 112 '@vars' => print_r($vars, TRUE)), WATCHDOG_DEBUG); 113 } 114 115 $url = simple_paypal_get_url(); 116 $ch = curl_init(); 117 118 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 119 curl_setopt($ch, CURLOPT_URL, $url); 120 curl_setopt($ch, CURLOPT_POST, 1); 121 curl_setopt($ch, CURLOPT_POSTFIELDS, simple_paypal_post($vars)); 122 123 ob_start(); 124 125 if (curl_exec($ch)) { 126 $info = ob_get_contents(); 127 curl_close($ch); 128 ob_end_clean(); 129 130 if (eregi('VERIFIED', $info)) { 131 return TRUE; 132 } 133 else { 134 return FALSE; 135 } 136 } 137 else { 138 watchdog('simple_paypal', 'Call to curl_exec() failed. url=@url vars=@vars', array( 139 '@vars' => print_r($vars, TRUE), 140 '@url' => $url, 141 ), WATCHDOG_ERROR); 142 return FALSE; 143 } 144 } 145 146 function simple_paypal_post($data = array()) { 147 $post = ''; 148 foreach ($data as $key => $value) { 149 $post .= $key. '='. urlencode($value). '&'; 150 } 151 $post .= 'cmd=_notify-validate'; 152 153 return $post; 154 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |