/[drupal]/contributions/sandbox/frjo/payson/payson.module
ViewVC logotype

Contents of /contributions/sandbox/frjo/payson/payson.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Apr 5 15:29:54 2005 UTC (4 years, 7 months ago) by frjo
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Payson module for ecommerce module
1 <?php
2 // $Id: payson.module,v 1.11 2004/10/01 00:08:31 uwe Exp $
3
4 /********************************************************************
5 * Drupal Hooks
6 ********************************************************************/
7
8 /**
9 * Provide online user help
10 *
11 * By implementing hook_help(), a module can make documentation
12 * available to the engine or to other modules. All user help should be
13 * returned using this hook; developer help should be provided with
14 * PHPDoc/Doxygen comments.
15 */
16 function payson_help($section = 'admin/help#payson') {
17
18 switch ($section) {
19 case 'admin/modules#description':
20 $output = t('Process payments using Payson.');
21 break;
22
23 case 'admin/settings/payson':
24 global $base_url;
25 $output = t("<p>In order to use this module, you need to create an account with Payson.</p>");
26 break;
27 }
28
29 return $output;
30 }
31
32 /**
33 * Implementation of menu_hook()
34
35 function payson_menu() {
36
37 $items = array();
38 $items[] = array('path' => 'payson/ipn', 'title' => t('payson IPN'),
39 'callback' => 'payson_ipn',
40 'access' => true,
41 'type' => MENU_CALLBACK);
42 return $items;
43 }
44 */
45
46 function payson_settings() {
47 $output = form_textfield(t('Payson Receiver Email'), 'payson_receiver_email', variable_get('payson_receiver_email', variable_get('site_mail', '')), 70, 180, t('Primary email address of the payment recipent. This is also your main Payson email address.'));
48 $output .= form_textfield(t('Payson Guarantee'), 'payson_guarantee', variable_get('payson_guarantee', '0'), 70, 180, t('0=Offer Payson Guarantee, the buyer pays the fees. 1=Do not offer Payson Guarantee, the seller pays the fees.'));
49 $output .= form_textfield(t('Payson processing URL'), 'payson_url', variable_get('payson_url', 'https://www.payson.se/prod/PaysonStart.aspx'), 70, 180, t('URL of the secure payment page customers are sent to for payment processing.'));
50 $output .= form_textfield(t('Payson MD5 key'), 'payson_md5', variable_get('payson_md5', ''), 70, 180, t('Your Payson MD5 key.'));
51 $output .= form_textfield(t('Payson AgentID'), 'payson_agentid', variable_get('payson_agentid', ''), 70, 180, t('Your Payson AgentID.'));
52 $output .= form_textfield(t('Successful payment URL'), 'payson_return_url', variable_get('payson_return_url', 'node'), 70, 180, t("This is the destination to which you would like to send your customers when their payment has been successfully completed. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
53 $output .= form_textfield(t('Cancel payment URL'), "payson_cancel_url", variable_get("payson_cancel_url", "node"), 70, 180, t("This is the destination to which you would like to send your customers if they cancel their payment. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
54
55 return $output;
56 }
57
58 /********************************************************************
59 * Default payment Method Functions
60 *
61 * - I wanted to have a default payment calculation method, and this
62 * seemed like the best place to put it.
63 ********************************************************************/
64
65 /**
66 * The Controller to create a new payment interface.
67 */
68 function payson_paymentapi(&$data, $op, $arg) {
69
70 if (user_access('access content')) {
71
72 switch ($op) {
73
74 case 'display name':
75 return t("Payson");
76 break;
77
78 case 'update':
79 return payson_save($data);
80 break;
81
82 case 'insert':
83 return payson_save($data);
84 break;
85
86 case 'redirect':
87 return payson_goto($data);
88 break;
89
90 case 'delete':
91 payson_delete($data);
92 break;
93 }
94 }
95 }
96
97 function payson_delete($data) {
98 db_query('DELETE FROM {ec_payson} WHERE txnid = %d', $data['txnid']);
99 }
100
101 function payson_goto($edit, $txnid = true) {
102
103 global $user;
104
105 if ($txnid) {
106 $txnid = $edit['txnid'];
107 }
108
109 global $base_url;
110 $shop_name = variable_get('shop_name', variable_get('site_name', 'drupal'));
111 $seller_email = variable_get('payson_receiver_email', variable_get("site_mail", ''));
112 $buyer_email = $user->mail ? $user->mail : $edit[mail];
113 $item_name = $user->uid ? $shop_name. ' order #'. $txnid. " for $user->name" : $shop_name. ' order #'. $txnid;
114 $return_url = (!strstr(variable_get('payson_return_url', 'node'), 'http://')) ? $base_url. '/'. variable_get("payson_return_url", 'node') : variable_get("payson_return_url", 'node');
115 $cancel_url = (!strstr(variable_get('payson_cancel_url', 'node'), 'http://')) ? $base_url. '/'. variable_get("payson_cancel_url", 'node') : variable_get("payson_cancel_url", 'node');
116 $extra_cost = $edit['shipping_cost'] ? $edit['shipping_cost'] : '0';
117 $md5key = variable_get('payson_md5', '');
118
119 $uri_array = array('SellerEmail' => $seller_email,
120 'BuyerEmail' => $buyer_email,
121 'Description' => $item_name,
122 'RefNr' => $txnid,
123 'Cost' => $edit['subtotal'],
124 'ExtraCost' => $extra_cost,
125 'ShippingType' => 1,
126 'GuaranteeOffered' => variable_get('payson_guarantee', '0'),
127 'OkUrl' => $return_url,
128 'CancelUrl' => $cancel_url,
129 'AgentId' => variable_get('payson_agentid', '')
130 );
131
132 foreach($uri_array as $key => $value) {
133 if ($value) {
134 $value = urlencode($value);
135 }
136 $uri .= "&$key=". $value;
137 }
138
139 $uri = substr($uri, 1);
140
141 $md5_string = $seller_email .":";
142 $md5_string .= $uri_array['Cost'] .":";
143 $md5_string .= $extra_cost .":";
144 $md5_string .= $return_url .":";
145 $md5_string .= $uri_array['GuaranteeOffered'] . $md5key;
146 $md5_hash = md5($md5_string);
147
148 $uri .= "&MD5=". $md5_hash;
149
150 $url = variable_get('payson_url', "https://www.payson.se/prod/PaysonStart.aspx") ."?". $uri;
151
152 $to = $seller_email;
153 $from = $buyer_email;
154 $headers = "From: $from\nReply-to: $from\nX-Mailer: PHP\nReturn-path: $from\nErrors-to: $from";
155 $subject = $item_name;
156 $body = t("Payson request from ecommerce\n");
157 $body .= "--------------------------------------------------\n";
158 $body .= $subject ."\n";
159 $body .= "Cost:". $edit['subtotal'] ."\n";
160 $body .= "--------------------------------------------------\n";
161
162 user_mail($to, $subject, $body, $headers);
163
164 $is_new = (db_result(db_query('SELECT COUNT(txnid) FROM {ec_payson} WHERE ppid = %d', $ppid))) ? false : true;
165
166 if ($is_new && $txnid) {
167 /* Compose and send confirmation email to the user */
168 store_send_invoice_email($txnid);
169 }
170 else {
171 store_send_error_email($txnid);
172 }
173
174 /* I can't use drupal_goto() becuase paypal will choke if the session ID is passed since it appends a '?' instead of a '&'. */
175 header("Location: $url");
176 }
177
178 function payson_save($edit) {
179
180 if ($edit['txnid'] && $edit['ppid']) {
181
182 if (db_result(db_query("SELECT COUNT(txnid) FROM {ec_payson} WHERE txnid = '%s'", $edit['txnid']))) {
183 db_query("UPDATE {ec_payson} SET ppid = '%s', fee = '%s' WHERE txnid = '%d'", $edit['ppid'], $edit['fee'], $edit['txnid']);
184 }
185 else {
186 db_query("INSERT INTO {ec_payson} (txnid, ppid, fee) VALUES ('%d', '%s', '%s')", $edit['txnid'], $edit['ppid'], $edit['fee']);
187 }
188 }
189
190 }
191
192 ?>

  ViewVC Help
Powered by ViewVC 1.1.2