SHARE
TWEET

Untitled

a guest Jan 27th, 2014 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  * Credit card payment
  6.  */
  7.  
  8.  
  9. /**
  10.  * Implements hook_commerce_payment_method_info().
  11.  */
  12. function commerce_payment_credit_card_commerce_payment_method_info() {
  13.   $payment_methods = array();
  14.  
  15.   $payment_methods['commerce_payment_credit_card'] = array(
  16.     'title' => t('Credit Card'),
  17.     'description' => t('Credit card payment type'),
  18.     'active' => TRUE,
  19.   );
  20.  
  21.   return $payment_methods;
  22. }
  23.  
  24. /**
  25.  * Payment method callback: submit form.
  26.  */
  27.  
  28.  
  29. function commerce_payment_credit_card_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
  30.   $form = array();
  31.  
  32.   // Merge in values from the order.
  33.   if (!empty($order->data['commerce_payment_credit_card'])) {
  34.     $pane_values += $order->data['commerce_payment_credit_card'];
  35.   }
  36.  
  37.   // Merge in default values.
  38.   $pane_values += array(
  39.     'credit_card' => '',
  40.   );
  41.  
  42.  
  43. $form['card_on_file'] = array(
  44.   '#type' => 'entityreference',
  45.   '#title' => t('Credit Card'),
  46.   '#era_entity_type' => 'node',  // Mandatory.
  47.   '#era_bundles' => array(credit_card), // Optional (Any bundle by default).
  48.   '#era_cardinality' => 5,       // Optional (1 By default).
  49.   '#required' => TRUE,
  50.   );
  51.  
  52.   return $form;
  53.  
  54. }
  55.  
  56.  
  57.  
  58. /**
  59.  * Payment method callback: submit form submission.
  60.  */
  61. function commerce_payment_credit_card_submit_form_submit($payment_method, $pane_form, $pane_values, $order, $charge) {
  62.  
  63.   $order->data['commerce_payment_credit_card'] = $pane_values;
  64.  
  65.   commerce_payment_credit_card_transaction($payment_method, $order, $charge, $pane_values['card_on_file']);
  66. }
  67.  
  68. /**
  69.  * Creates an example payment transaction for the specified charge amount.
  70.  *
  71.  * @param $payment_method
  72.  *   The payment method instance object used to charge this payment.
  73.  * @param $order
  74.  *   The order object the payment applies to.
  75.  * @param $charge
  76.  *   An array indicating the amount and currency code to charge.
  77.  * @param $card_on_file
  78.  *   The card entered on the submission form.
  79.  */
  80. function commerce_payment_credit_card_transaction($payment_method, $order, $charge, $card_on_file) {
  81.   $transaction = commerce_payment_transaction_new('commerce_payment_credit_card', $order->order_id);
  82.   $transaction->instance_id = $payment_method['instance_id'];
  83.   $transaction->amount = $charge['amount'];
  84.   $transaction->currency_code = $charge['currency_code'];
  85.   $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
  86.   $transaction->message = t('@card_on_file');
  87.   $transaction->message_variables = array('@card_on_file' => $card_on_file);
  88.  
  89.   commerce_payment_transaction_save($transaction);
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top