-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgapi.module
834 lines (721 loc) · 21.5 KB
/
pgapi.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
<?php
// No payment information has been recieved.
define('PG_PENDING', 1);
// Payment has been completed and confirmed and money has been transfered.
define('PG_COMPLETED', 2);
// Payment failed.
define('PG_FAILED', 3);
//Payment has been denied.
define('PG_DENIED', 4);
// Payment has been refunded.
define('PG_REFUNDED', 5);
// Payment has been canceled.
define('PG_CANCELED', 6);
// Payment recieved but not confirmed.
define('PG_RECEIVED', 7);
// The transaction has been received.
define('PG_WORKFLOW_RECEIVED', 1);
// Transaction has been invoiced. This means an invoice has been printed or viewed.
define('PG_WORKFLOW_INVOICED', 2);
// The transaction has been shipped.
define('PG_WORKFLOW_SHIPPED', 3);
// The transaction is awaiting a customer responce before it can continue.
define('PG_WORKFLOW_AWAITING_RESPONSE', 4);
// The transaction has been canceled.
define('PG_WORKFLOW_CANCELED', 5);
// The transaction is completed.
define('PG_WORKFLOW_COMPLETED', 6);
// A security violation has been detected and the transaction has been taken out of the general workflow and flagged.
define('PG_WORKFLOW_SECURITY_VIOLATION', 7);
/**
* Implements hook_menu().
*/
function pgapi_menu() {
$items = array();
$items['payment/%pgapi_transaction'] = array(
'title callback' => 'pgapi_payment_title',
'title arguments' => array(1),
'page callback' => 'pgapi_payment_page',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin/config/pgapi'] = array(
'title' => 'Payment Gateway API Tools',
'description' => "Manage Payment Gateway API's Tools.",
'position' => 'right',
'weight' => 7,
'page callback' => 'pgapi_admin_menu_block_page',
'access arguments' => array('administer pgapi'),
'file' => 'pgapi.admin.inc',
);
$items['admin/config/pgapi/gateway_settings'] = array(
'title' => 'Payment Gateway API Settings',
'description' => 'Configure gateway settings for Payment Gateway API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('pgapi_admin_gateway_settings'),
'access arguments' => array('administer pgapi'),
'file' => 'pgapi.admin.inc',
'weight' => -10,
);
$items['admin/config/pgapi/gateway_settings/common'] = array(
'title' => 'Active gateways',
'description' => 'Configure gateway settings for Payment Gateway API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('pgapi_admin_gateway_settings'),
'access arguments' => array('administer pgapi'),
'file' => 'pgapi.admin.inc',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/config/pgapi/currency_settings'] = array(
'title' => 'Payment Gateway Currency Settings',
'description' => 'Configure currency settings for Payment Gateway API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('pgapi_admin_currency_settings'),
'access arguments' => array('administer pgapi'),
'file' => 'pgapi.admin.inc',
'weight' => -11,
);
$items['admin/config/pgapi/notices_settings'] = array(
'title' => 'Payment Notices Settings',
'description' => 'Configure notices settings for Payment Gateway API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('pgapi_admin_notices_settings'),
'access arguments' => array('administer pgapi'),
'file' => 'pgapi.admin.inc',
'weight' => -12,
);
return $items;
}
/**
* Implements hook_permission().
*/
function pgapi_permission() {
// Add permission to admin pgapi.
return array(
'administer pgapi' => array(
'title' => t('Administer pgapi'),
'description' => t('Allows to choose payment gateways and change configurations'),
'restrict access' => TRUE,
),
);
}
/**
* Implements hook_theme().
*/
function pgapi_theme() {
return array(
'payment' => array(
'render element' => 'elements',
'template' => 'payment',
'file' => 'pgapi.theme.inc',
),
'pgapi_format_price' => array(
'variables' => array(
'price' => NULL,
'symbol' => NULL,
'position' => NULL,
),
'file' => 'pgapi.theme.inc',
),
'pgapi_format_price_plain' => array(
'variables' => array(
'price' => NULL,
'symbol' => NULL,
'position' => NULL,
),
'file' => 'pgapi.theme.inc',
),
);
}
/**
* Implements of hook_views_api().
*/
function pgapi_views_api() {
return array(
'api' => 2,
);
}
/**
* Implemens hook_mail().
*
* @todo replace with settings page for email template with tokens.
*/
function pgapi_mail($key, &$message, $params) {
$template = pgapi_mail_template($key, $message, $params);
$message['subject'] = $template->subject;
$message['body'] = $template->body;
}
/**
* Mail templates.
*
* @param $key
* Mail key.
*
* @param $message
* Array setting messages.
*
* @param $params
* Params for mail.
*
* @return object
* Subject and message text.
*/
function pgapi_mail_template($key, $message, $params) {
$language = $message['language'];
if (!$language) {
global $language;
}
$transaction = $params['transaction'];
$account = user_load($transaction->uid);
$variables = array();
$variables['!username'] = $account->name;
$variables['!txnid'] = $transaction->txnid;
$variables['!pg_amount'] = $transaction->amount;
// @todo Preserve old type and method tokens?
$variables['!pg_type'] = $transaction->service;
$variables['!pg_method'] = $transaction->gateway;
// @todo Emails are not using this values because upgraded can have the messages translated.
$variables['!pg_service'] = $transaction->service;
$variables['!pg_gateway'] = $transaction->gateway;
$variables['!status'] = pgapi_get_status($transaction->status);
$variables['!workflow'] = pgapi_get_workflow($transaction->workflow);
$variables['!site'] = variable_get('site_name', '');
// @todo: get mail subject and body from settings form.
switch ($key) {
case PG_PENDING:
$message['subject'] = t('New Payment Notification from !site', $variables, array('langcode' => $language->language));
$message['body'][] = t("Dear !username\nPayment #!txnid has been created.\n\nAmount: !pg_amount\nType: !pg_type\nMethod: !pg_method\n\nBest regards,\n!site", $variables, array('langcode' => $language->language));
break;
default:
$message['subject'] = t('Payment !txnid Change Notification from !site', $variables, array('langcode' => $language->language));
$message['body'][] = t("Dear !username\nPayment #!txnid has been changed.\n\nAmount: !pg_amount\nType: !pg_type\nMethod: !pg_method\nStatus: !status\nWorkflow: !workflow\n\nBest regards,\n!site", $variables, array('langcode' => $language->language));
}
return (object) $message;
}
/**
* Returns html formated price.
*
* @see hook_pgapi_format_price()
*
* @param number $price
* String with price to format.
*
* @param string $format
* String with format.
*
* @return string
* Formatted price with price symbol.
*/
function pgapi_format_price($price, $format = NULL) {
if (empty($format)) {
$format = variable_get('pgapi_currency', array());
}
if ($format) {
$formated_price = number_format((double) $price, $format['decimal_places'], $format['decimal'], $format['thousands']);
$formated = theme('pgapi_format_price', array(
'price' => $formated_price,
'symbol' => $format['symbol'],
'position' => isset($format['symbol_position']) ? $format['symbol_position'] : TRUE,
));
}
else {
$formated_price = number_format($price, 2, '.', ',');
$formated = theme('pgapi_format_price', array(
'price' => $formated_price,
'symbol' => '$',
'position' => TRUE,
));
}
return $formated;
}
/**
* Return formated price without html.
*
* Add hook_pgapi_format_price().
*
* @param number $price
* String with price to format.
*
* @return string
* Formatted price with price symbol.
*/
function pgapi_format_price_plain($price) {
$format = variable_get('pgapi_currency', array());
if ($format) {
$formated_price = number_format($price, $format['decimal_places'], $format['decimal'], $format['thousands']);
$formated = theme('pgapi_format_price_plain', array(
'price' => $formated_price,
'symbol' => $format['symbol'],
'position' => $format['symbol_position'],
));
}
else {
$formated_price = number_format($price, 2, '.', ',');
$formated = theme('pgapi_format_price_plain', array(
'price' => $formated_price,
'symbol' => '$',
'position' => TRUE,
));
}
return $formated;
}
/**
* Returns array with enabled payment systems.
*/
function pgapi_get_enabled_payment_systems() {
$pgapi_gw = variable_get('pgapi_gw', array());
return $pgapi_gw;
}
/**
* Save or update transaction.
*
* Add hook_pgapi_transaction().
* Add hook_pgapi_transaction_all().
*
* @param object $transaction
* Object transaction.
*
* @todo fix user_preferred_language to admin.
*/
function pgapi_transaction_save(&$transaction) {
global $user;
$time = time();
$transaction->is_new = FALSE;
// Set last changed time.
if (!isset($transaction->changed)) {
$transaction->changed = $time;
}
// Set transaction author.
if (!isset($transaction->uid)) {
$transaction->uid = $user->uid;
}
if (!isset($transaction->email) && $user->uid) {
$transaction->email = $user->mail;
}
// If this is new transaction.
if (!isset($transaction->txnid)) {
// Set timestamp when transaction was created.
if (!isset($transaction->created)) {
$transaction->created = $time;
$transaction->changed = $time;
}
// Default transaction status is pending.
if (!isset($transaction->status)) {
$transaction->status = pgapi_get_status_id('pending');
}
// Default workflow status is pending.
if (!isset($transaction->workflow)) {
$transaction->workflow = pgapi_get_workflow_id('received');
}
// Set new flag.
$transaction->is_new = TRUE;
}
if (empty($transaction->description)) {
// Blob text should have a value.
$transaction->description = '';
}
if ($transaction->is_new) {
// Save transaction.
if (!isset($transaction->extra)) {
$transaction->extra = array();
}
$transaction->extra = serialize($transaction->extra);
drupal_write_record('pgapi_transaction', $transaction);
}
else {
// Allow involved service and gateway to update the transactions.
module_invoke($transaction->service, 'pgapi_transaction', $transaction->status, $transaction, 'service');
module_invoke($transaction->gateway, 'pgapi_transaction', $transaction->status, $transaction, 'gateway');
// Update main transaction.
if (isset($transaction->extra)) {
$transaction->extra = serialize($transaction->extra);
}
drupal_write_record('pgapi_transaction', $transaction, 'txnid');
}
// Send mail to admin.
if (variable_get('pgapi_notice_admin', FALSE)) {
if ($transaction->status == PG_COMPLETED) {
// @todo: Add settings admin email on pgapi module.
$admin_mail = variable_get('pgapi_email', '');
if (!$admin_mail) {
$admin_mail = variable_get('site_mail', '');
}
$params['transaction'] = $transaction;
if (module_exists('notices')) {
$user_admin = user_load(1);
$template = pgapi_mail_template($transaction->status, array(
'language' => user_preferred_language($user_admin),
), $params);
$notice = new stdClass();
$notice->uid = $user_admin->uid;
$notice->provider = 'notices_node';
$notice->subject = $template->subject;
$notice->message = $template->body[0];
$notice->format = filter_default_format($user_admin);
notices_save($notice);
}
else {
drupal_mail('pgapi', $transaction->status, $admin_mail, user_preferred_language($user), $params);
}
}
}
// Unserialize extra data.
$transaction->extra = unserialize($transaction->extra);
// Call hook_pgapi_transaction_all().
module_invoke_all('pgapi_transaction_all', $transaction->status, $transaction);
}
/**
* Loads transaction by ID.
*
* Used as menu autoload function.
*
* @param int $txnid
* Transaction ID.
*
* @return object
* Loaded transaction.
*/
function pgapi_transaction_load($txnid) {
if (ctype_digit($txnid)) {
$transaction = db_query("SELECT * FROM {pgapi_transaction} WHERE txnid = :txnid", array(':txnid' => $txnid))->fetchObject();
if ($transaction) {
// Unserialize data.
$transaction->extra = unserialize($transaction->extra);
return $transaction;
}
}
return FALSE;
}
/**
* Deletes transaction.
*
* @param int $txnid
* Transaction ID.
*/
function pgapi_transaction_delete($txnid) {
db_delete('pgapi_transaction')
->condition('txnid', $txnid)
->execute();
}
/**
* Returns all payment gateways.
*
* @return array
* Array with payment gateways.
*/
function pgapi_get_gateway_options() {
$methods = array();
// Get all hook_pgapi_gw() implementations.
$implementations = module_implements('pgapi_gw');
foreach ($implementations as $module) {
if ($module_name = module_invoke($module, 'pgapi_gw', 'display name')) {
$methods[$module] = $module_name;
}
}
return $methods;
}
/**
* Get payment gateway name from module.
*
* @param string $module
* Module name.
*
* @return string
* Gateway name.
*/
function pgapi_get_gateway_name($module) {
return module_invoke($module, 'pgapi_gw', 'display name');
}
/**
* Get all availible transaction statuses.
*
* Add hook_pgapi_transaction_status().
*
* @return array
* List statuses.
*/
function pgapi_build_status() {
$status = array(
PG_PENDING => t('pending'),
PG_COMPLETED => t('completed'),
PG_FAILED => t('failed'),
PG_DENIED => t('denied'),
PG_REFUNDED => t('refunded'),
PG_CANCELED => t('canceled'),
PG_RECEIVED => t('received'),
);
// Get all hook_pgapi_transaction_status() implementations.
$implementations = module_implements('pgapi_transaction_status');
foreach ($implementations as $module) {
module_invoke($module, 'pgapi_transaction_status', $status);
}
// Return array with all statuses.
return $status;
}
/**
* Return human-readable status name.
*
* @param int $id
* Status ID.
*
* @return string
* Status name.
*/
function pgapi_get_status($id) {
$status = pgapi_build_status();
if ($status[$id]) {
return $status[$id];
}
return t('undefined status');
}
/**
* Return status ID by human-readable status name.
*
* @param string $name
* String with status name.
*
* @return int
* Status ID.
*/
function pgapi_get_status_id($name) {
$name = drupal_strtolower(t($name));
$statuses = pgapi_build_status();
$status_id = array_search($name, $statuses);
if ($status_id) {
return $status_id;
}
return 0;
}
/**
* Get all availible transaction workflows.
*
* Add hook_pgapi_transaction_workflow()
*
* @return array
* Return array with all workflows.
*/
function pgapi_build_workflow() {
$workflow = array(
PG_WORKFLOW_RECEIVED => t('received'),
PG_WORKFLOW_INVOICED => t('invoiced'),
PG_WORKFLOW_SHIPPED => t('shipped'),
PG_WORKFLOW_AWAITING_RESPONSE => t('awaiting customer response'),
PG_WORKFLOW_CANCELED => t('canceled'),
PG_WORKFLOW_COMPLETED => t('completed'),
PG_WORKFLOW_SECURITY_VIOLATION => t('security violation'),
);
// Get all hook_pgapi_transaction_workflow() implementations.
$implementations = module_implements('pgapi_transaction_workflow');
foreach ($implementations as $module) {
module_invoke($module, 'pgapi_transaction_workflow', $workflow);
}
// Return array with all workflows.
return $workflow;
}
/**
* Return human-readable workflow name.
*
* @param int $id
* Workflow ID.
*
* @return string
* Workflow name.
*/
function pgapi_get_workflow($id) {
$workflow = pgapi_build_workflow();
if ($workflow[$id]) {
return $workflow[$id];
}
return t('undefined workflow');
}
/**
* Return workflow ID by human-readable workflow name.
*
* @param string $name
* String with workflow name.
*
* @return int
* Workflow ID.
*/
function pgapi_get_workflow_id($name) {
$name = drupal_strtolower(t($name));
$statuses = pgapi_build_workflow();
$status_id = array_search($name, $statuses);
if ($status_id) {
return $status_id;
}
return 0;
}
/**
* Title callback for payment/% page.
*
* Return title of transaction.
*
* @param object $transaction
* Current transaction.
*
* @return string
* Title.
*/
function pgapi_payment_title($transaction) {
return strip_tags($transaction->title);
}
/**
* Page callback for payment/% page.
*
* Return form with payment methods.
*
* @param object $transaction
* Current transaction.
*
* @return string
* Form.
*/
function pgapi_payment_page($transaction) {
global $user;
// If someone tries to view not own page before transaction status
// is pending - show access denied page.
if (($user->uid != 1 && $user->uid != $transaction->uid)) {
drupal_access_denied();
}
if (module_exists($transaction->gateway)) {
module_invoke($transaction->gateway, 'pgapi_payment_page', $transaction);
}
$output = '';
$output .= theme('payment', array('transaction' => $transaction));
drupal_add_css(drupal_get_path('module', 'pgapi') . '/pgapi.css');
if ($transaction->status == PG_PENDING) {
$form = drupal_get_form('pgapi_payment', $transaction);
$output .= drupal_render($form);
}
return $output;
}
/**
* Implements hook_FORMID().
*/
function pgapi_payment($form, &$form_state, $transaction) {
drupal_add_css(drupal_get_path('module', 'pgapi') . '/pgapi.css');
if (($transaction->status != PG_PENDING) || ($transaction->workflow != PG_WORKFLOW_RECEIVED)) {
drupal_access_denied();
}
// Get array with enabled payment systems.
$pgapi_gw = pgapi_get_enabled_payment_systems();
$default = '';
$options = array();
foreach ($pgapi_gw as $module => $checked) {
if ($checked) {
// Get data about payment gateway from hook_pgapi_gw().
$payment_data = module_invoke($module, 'pgapi_gw', 'payment gateway info', $transaction->amount, $transaction);
if ($payment_data) {
if ($transaction->gateway == $module) {
$default = $transaction->gateway;
}
else {
$default = $module;
}
$form[$module]['modulename'] = array(
'#value' => $payment_data['name'],
);
$prices = '';
foreach ($payment_data['price'] as $cur => $price) {
$prices .= pgapi_format_price($price, array(
'decimal_places' => 2,
'decimal' => '.',
'thousands' => ',',
'symbol_position' => 1,
'symbol' => $cur,
));
}
$form[$module]['price'] = array(
'#value' => $prices,
);
$options[$module]['name'] = $payment_data['name'];
$options[$module]['price'] = $prices;
}
}
$form['description'] = array(
'#markup' => t('Please select service that you like to pay with.'),
);
$form['gateway'] = array(
'#type' => 'tableselect',
'#multiple' => FALSE,
'#header' => array(
'name' => t('Payment system'),
'price' => t('Amount to pay'),
),
'#options' => $options,
'#default_value' => $default,
'#empty' => t('Please contact website admin. No one payment gateway are enabled.'),
'#ajax' => array(
'wrapper' => 'pgapi-wrapper-form',
'callback' => 'pgapi_ajax_form_callback',
'effect' => 'slide',
'progress' => array(
'type' => 'none',
),
),
);
}
$form['pgapi_wrapper'] = array(
'#prefix' => '<div id = "pgapi-wrapper-form">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
$form['txnid'] = array(
'#type' => 'value',
'#value' => $transaction->txnid,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Process purchase'),
'#submit' => array('pgapi_payment_submit'),
'#validate' => array('pgapi_payment_validate'),
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel purchase'),
);
if (!empty($form_state['values']['gateway'])) {
$default = $form_state['values']['gateway'];
}
$data = module_invoke($default, 'pgapi_gw', 'ajax_form', $transaction);
if (is_array($data)) {
$form['pgapi_wrapper'] += $data['element'];
$form['submit']['#submit'][] = $data['submit'];
}
return $form;
}
function pgapi_ajax_form_callback($form, &$form_state) {
return $form['pgapi_wrapper'];
}
function pgapi_payment_validate($form, &$form_state) {
$values = $form_state['values'];
if (!isset($values['gateway'])) {
form_set_error('gateway', t('For continuing to choose a payment system.'));
}
}
/**
* Submit function for payment form. Process transaction and redirect
* to payment system page.
*/
function pgapi_payment_submit($form, &$form_state) {
$values = $form_state['values'];
if ($values['txnid']) {
// Load transaction by ID.
$transaction = pgapi_transaction_load($values['txnid']);
if ($values['op'] == $values['submit']) {
$transaction->gateway = $values['gateway'];
pgapi_transaction_save($transaction);
}
elseif ($values['op'] == $values['cancel']) {
// If user clicked "Cancel" button - cancel transaction.
$transaction->status = PG_CANCELED;
$transaction->workflow = PG_WORKFLOW_CANCELED;
$transaction->description = t('User canceled payment');
pgapi_transaction_save($transaction);
drupal_goto('payment/' . $transaction->txnid);
}
}
}