| 4 |
define('SIMPLE_PAYPAL_URL_TEST', 1); |
define('SIMPLE_PAYPAL_URL_TEST', 1); |
| 5 |
|
|
| 6 |
define('SIMPLE_PAYPAL_URL', 'simple_paypal_url'); |
define('SIMPLE_PAYPAL_URL', 'simple_paypal_url'); |
| 7 |
|
define('SIMPLE_PAYPAL_DEFAULT_CURRENCY', 'simple_paypal_default_currency'); |
| 8 |
|
|
| 9 |
function simple_paypal_get_urls() { |
function simple_paypal_get_urls() { |
| 10 |
return array( |
return array( |
| 11 |
SIMPLE_PAYPAL_URL_LIVE => 'https://www.paypal.com/cgi-bin/webscr', |
SIMPLE_PAYPAL_URL_LIVE => 'https://www.paypal.com/cgi-bin/webscr', |
| 12 |
SIMPLE_PAYPAL_URL_TEST => 'https://www.eliteweaver.co.uk/cgi-bin/webscr', |
SIMPLE_PAYPAL_URL_TEST => 'https://www.sandbox.paypal.com/cgi-bin/webscr', |
| 13 |
); |
); |
| 14 |
} |
} |
| 15 |
|
|
| 16 |
function simple_paypal_menu($may_cache) { |
/** |
| 17 |
$items = array(); |
* Implementation of hook_menu(). |
| 18 |
|
*/ |
| 19 |
if ($may_cache) { |
function simple_paypal_menu() { |
| 20 |
$items[] = array( |
$items = array(); |
| 21 |
'path' => 'admin/settings/paypal', |
|
| 22 |
'title' => t('Paypal'), |
$items['admin/settings/paypal'] = array( |
| 23 |
'callback' => 'drupal_get_form', |
'title' => 'Paypal', |
| 24 |
'callback arguments' => array('simple_paypal_settings'), |
'page callback' => 'drupal_get_form', |
| 25 |
'description' => t('Administer Paypal'), |
'page arguments' => array('simple_paypal_admin'), |
| 26 |
'access' => user_access('administer site configuration'), |
'description' => 'Administer Paypal', |
| 27 |
); |
'access arguments' => array('access administration pages'), |
| 28 |
} |
'type' => MENU_NORMAL_ITEM, |
| 29 |
|
); |
| 30 |
return $items; |
|
| 31 |
} |
return $items; |
| 32 |
|
} |
| 33 |
function simple_paypal_settings() { |
|
| 34 |
|
/** |
| 35 |
|
* Implementation of hook_admin(). |
| 36 |
|
*/ |
| 37 |
|
function simple_paypal_admin() { |
| 38 |
$form[SIMPLE_PAYPAL_URL] = array( |
$form[SIMPLE_PAYPAL_URL] = array( |
| 39 |
'#type' => 'select', |
'#type' => 'select', |
| 40 |
'#title' => t('Payment URL for Paypal'), |
'#title' => t('Payment URL for Paypal'), |
| 42 |
'#options' => simple_paypal_get_urls(), |
'#options' => simple_paypal_get_urls(), |
| 43 |
'#description' => t('Select whether you want to use a live URL, or a test one.'), |
'#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); |
return system_settings_form($form); |
| 52 |
} |
} |
| 53 |
|
|
| 57 |
} |
} |
| 58 |
|
|
| 59 |
function simple_paypal_get_currencies() { |
function simple_paypal_get_currencies() { |
| 60 |
return array( |
$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'), |
'EUR' => t('Euro'), |
| 68 |
'USD' => t('US Dollar') |
'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) { |
function simple_paypal_format_amount($amount, $currency) { |
| 95 |
$amount = number_format($amount, 2); |
$amount = number_format($amount, 2); |
| 96 |
switch($currency) { |
switch ($currency) { |
| 97 |
case 'EUR': |
case 'EUR': |
| 98 |
return "€ $amount"; |
return "€ $amount"; |
| 99 |
|
case 'GBP': |
| 100 |
|
return "£ $amount"; |
| 101 |
case 'USD': |
case 'USD': |
| 102 |
return "$ $amount"; |
return "$ $amount"; |
| 103 |
default: |
default: |
| 108 |
function simple_paypal_ipn_verify($vars = array()) { |
function simple_paypal_ipn_verify($vars = array()) { |
| 109 |
// If we are in test mode, log the variables. |
// If we are in test mode, log the variables. |
| 110 |
if (SIMPLE_PAYPAL_URL_TEST == variable_get(SIMPLE_PAYPAL_URL, SIMPLE_PAYPAL_URL_TEST)) { |
if (SIMPLE_PAYPAL_URL_TEST == variable_get(SIMPLE_PAYPAL_URL, SIMPLE_PAYPAL_URL_TEST)) { |
| 111 |
watchdog('debug', t('Post variables from Paypal IPN <pre>@vars</pre>', array( |
watchdog('simple_paypal', 'Post variables from Paypal IPN <pre>@vars</pre>', array( |
| 112 |
'@vars' => print_r($vars, TRUE)))); |
'@vars' => print_r($vars, TRUE)), WATCHDOG_DEBUG); |
| 113 |
} |
} |
| 114 |
|
|
| 115 |
$url = simple_paypal_get_url(); |
$url = simple_paypal_get_url(); |
| 135 |
} |
} |
| 136 |
} |
} |
| 137 |
else { |
else { |
| 138 |
watchdog('paypal', t('Call to curl_exec() failed. url=@url vars=@vars', array( |
watchdog('simple_paypal', 'Call to curl_exec() failed. url=@url vars=@vars', array( |
| 139 |
'@vars' => print_r($vars, TRUE), |
'@vars' => print_r($vars, TRUE), |
| 140 |
'@url' => $url, |
'@url' => $url, |
| 141 |
))); |
), WATCHDOG_ERROR); |
| 142 |
return FALSE; |
return FALSE; |
| 143 |
} |
} |
| 144 |
} |
} |
| 145 |
|
|
| 146 |
function simple_paypal_post($data = array()) { |
function simple_paypal_post($data = array()) { |
| 147 |
$post = ''; |
$post = ''; |
| 148 |
foreach($data as $key => $value) { |
foreach ($data as $key => $value) { |
| 149 |
$post .= $key . '=' . urlencode($value) . '&'; |
$post .= $key. '='. urlencode($value). '&'; |
| 150 |
} |
} |
| 151 |
$post .= 'cmd=_notify-validate'; |
$post .= 'cmd=_notify-validate'; |
| 152 |
|
|