/[drupal]/contributions/modules/uc_zpayment/uc_zpayment.module
ViewVC logotype

Contents of /contributions/modules/uc_zpayment/uc_zpayment.module

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Jan 14 01:41:31 2009 UTC (10 months, 1 week ago) by ibabushka
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA1, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of uc_zpayment module.
1 <?php
2 // $Id$
3 define("zpaymentActionUrl" ,"https://z-payment.ru/merchant.php");
4
5 /********************************************************************
6 * Drupal Hooks
7 ********************************************************************/
8
9 /**
10 * Implementation of hook_menu()
11 */
12
13 function uc_zpayment_menu() {
14
15 $items['cart/zpayment/complete'] = array(
16 'title' => t('Internal Data'),
17 'page callback' => 'uc_zpayment_complete',
18 'access callback' => 'uc_zpayment_complete_access',
19 'type' => MENU_CALLBACK,
20 'file' => 'uc_zpayment.pages.inc',
21 );
22 $items['cart/zpayment/finalize'] = array(
23 'title' => t('zpayment processing'),
24 'page callback' => 'uc_zpayment_finalize',
25 'access callback' => 'uc_zpayment_complete_access',
26 'type' => MENU_CALLBACK,
27 'file' => 'uc_zpayment.pages.inc',
28 );
29 $items['cart/zpayment/fail'] = array(
30 'title' => t('zpayment processing'),
31 'page callback' => 'uc_zpayment_fail',
32 'access callback' => 'uc_zpayment_complete_access',
33 'type' => MENU_CALLBACK,
34 'file' => 'uc_zpayment.pages.inc',
35 );
36
37 return $items;
38 }
39
40 // Make sure anyone can complete their Z-payment orders.
41 function uc_zpayment_complete_access() {
42 return TRUE;
43 }
44
45 /**
46 * Implementation of hook_form_alter().
47 */
48 function uc_zpayment_form_alter(&$form, &$form_state, $form_id) {
49
50 if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
51 $order = uc_order_load($order_id);
52
53 if ($order->payment_method == 'zpayment') {
54 unset($form['submit']);
55 $form['#prefix'] = '<table ><tr><td>';
56 $form['#suffix'] = '</td><td>'. drupal_get_form('uc_zpayment_form', $order) .'</td></tr></table>';
57 }
58 }
59 }
60
61
62 /********************************************************************
63 * Hook Functions (Ubercart)
64 ********************************************************************/
65
66 /**
67 * Implementation of hook_payment_method().
68 */
69 function uc_zpayment_payment_method() {
70 $path = base_path() . drupal_get_path('module', 'uc_zpayment');
71 $title = t('z-payment') . '<br /><img src="'. $path .'/images/zpayment.gif" style="position: relative; left: 2.5em;">';
72
73 $methods[] = array(
74 'id' => 'zpayment',
75 'name' => t('zpayment'),
76 'title' => $title,
77 'desc' => t('Redirect to zpayment.com.'),
78 'callback' => 'uc_payment_method_zpayment',
79 'weight' => 3,
80 'checkout' => TRUE,
81 'no_gateway' => TRUE,
82 );
83
84 return $methods;
85 }
86
87 /********************************************************************
88 * other Functions
89 ********************************************************************/
90 function uc_payment_method_zpayment($op, &$arg1) {
91 switch ($op) {
92 case 'cart-details':
93 return $details;
94 case 'settings':
95
96 $form['uc_zpayment_action_url'] = array(
97 '#type' => 'textfield',
98 '#title' => t('Action url'),
99 '#default_value' => variable_get('uc_zpayment_action_url',zpaymentActionUrl),
100 '#description' => t("Please enter action url.\nDefault: !url", array('!url' => zpaymentActionUrl)),
101 );
102
103
104 $form['uc_zpayment_store_id'] = array(
105 '#type' => 'textfield',
106 '#title' => t('Store id'),
107 '#default_value' => variable_get('uc_zpayment_store_id',''),
108 '#description' => t("Please enter Store id."),
109 '#required' => TRUE,
110 '#size' => 6,
111 );
112
113
114 // $form['uc_zpayment_success_url'] = array(
115 // '#type' => 'textfield',
116 // '#title' => t('Success URL'),
117 // '#default_value' => variable_get('uc_zpayment_success_url', ''),
118 // '#description' => t('Success URL'),
119 // '#required' => TRUE,
120 // );
121
122 return $form;
123 case 'cart-process':
124 return;
125 }
126 }
127
128
129 function uc_zpayment_form($form_state, $order) {
130
131 $amount = $order->order_total;
132 $ser['amount']=$amount;
133 $description=serialize($ser);
134 if (db_result(db_query("SELECT COUNT(txnid) FROM {uc_zpayment_transaction} WHERE txnid = '%s'", $order->order_id))) {
135 db_query("UPDATE {uc_zpayment_transaction} SET description = '%s' WHERE txnid = %d",$description, $order->order_id);
136 }else {
137 db_query("INSERT INTO {uc_zpayment_transaction} (txnid, description) VALUES (%d, '%s')", $order->order_id, $description);
138 }
139
140
141 $data_hidden = array(
142
143
144 );
145
146
147 // Shop id
148 $form['LMI_PAYEE_PURSE'] = array(
149 '#type' => 'hidden',
150 '#value' => variable_get('uc_zpayment_store_id', ''),
151 );
152
153 // Order id
154 $form['LMI_PAYMENT_NO'] = array(
155 '#type' => 'hidden',
156 '#value' => $order->order_id,
157 );
158
159 // Comment
160 $form['LMI_PAYMENT_DESC'] = array(
161 '#type' => 'hidden',
162 '#default_value' => t('Oplata zakaza'),
163 );
164
165 // User E-mail
166 $form['CLIENT_MAIL'] = array(
167 '#type' => 'hidden',
168 '#default_value' => $order->primary_email,
169 );
170
171 // Amount
172 $form['LMI_PAYMENT_AMOUNT'] = array(
173 '#type' => 'hidden',
174 '#value' => $amount,
175 );
176
177 $form['#action'] = variable_get('uc_zpayment_action_url',zpaymentActionUrl);
178 $form['submit'] = array(
179 '#type' => 'submit',
180 '#value' => t('Place your order'),
181 );
182 return $form;
183 }
184
185
186 // UTILS
187 function uc_zpayment_redirect_url($url = '') {
188
189 if( !$url ) $url = 'http://truecoach.ru';
190
191 // Javascript redirect on the finalization page.
192 $output = '<script type="text/javascript">window.location = "'. url($url, array('absolute' => TRUE)) .'";</script>';
193
194 // Text link for users without Javascript enabled.
195 $output .= l(t('Click to complete checkout.'), $url, array('absolute' => TRUE));
196
197 print $output;
198 exit();
199 }
200
201
202 //
203 function uc_zpayment_finalize ($order_id = 0){
204
205 if (intval($_SESSION['cart_order']) != $order_id) {
206 $_SESSION['cart_order'] = $order_id;
207 }
208
209 if(isset($_SESSION['cart_order'])){
210 $order_id = $_SESSION['cart_order'];
211 $_SESSION['do_complete'] = TRUE;
212 drupal_goto('cart/checkout/complete');
213 } else {
214 unset($_SESSION['cart_order']);
215 // drupal_set_message( t("Your payment has been declined."));
216 drupal_goto('cart');
217 }
218
219 }
220

  ViewVC Help
Powered by ViewVC 1.1.2