uc_payment.tokens.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. * Token hooks for the uc_payment module.
  5. */
  6. /**
  7. * Implements hook_token_info().
  8. */
  9. function uc_payment_token_info() {
  10. $order['payment-method'] = array(
  11. 'name' => t('Payment method'),
  12. 'description' => t('The payment method of the order.'),
  13. );
  14. $order['payment-balance'] = array(
  15. 'name' => t('Balance'),
  16. 'description' => t('The payment balance of the order'),
  17. );
  18. return array(
  19. 'tokens' => array('uc_order' => $order),
  20. );
  21. }
  22. /**
  23. * Implements hook_tokens().
  24. */
  25. function uc_payment_tokens($type, $tokens, $data = array(), $options = array()) {
  26. $values = array();
  27. if ($type == 'uc_order' && !empty($data['uc_order'])) {
  28. $order = $data['uc_order'];
  29. if (isset($tokens['payment-method'])) {
  30. $original = $tokens['payment-method'];
  31. $values[$original] = _uc_payment_method_data($order->payment_method, 'review');
  32. if (empty($values[$original])) {
  33. $values[$original] = _uc_payment_method_data($order->payment_method, 'name');
  34. }
  35. }
  36. if (isset($tokens['payment-balance'])) {
  37. $original = $tokens['payment-balance'];
  38. $values[$original] = uc_currency_format(uc_payment_balance($order));
  39. }
  40. }
  41. return $values;
  42. }