protected function getMultipleProductsInfo()
 {
     $order_lines = field_get_items('commerce_order', $this->datasources["order"], 'commerce_line_items');
     $line_item_ids = array();
     foreach ($order_lines as $order_line) {
         $line_item_ids[] = $order_line['line_item_id'];
     }
     $line_items = commerce_line_item_load_multiple($line_item_ids);
     $product_ids = array();
     $cant_prod = array();
     foreach ($line_items as $line_item) {
         $tmp = field_get_items('commerce_line_item', $line_item, 'commerce_product');
         $cant_prod[$tmp[0]['product_id']] = round($line_item->quantity);
         $product_ids[] = $tmp[0]['product_id'];
     }
     $products = commerce_product_load_multiple($product_ids);
     $code = array();
     $description = array();
     $name = array();
     $sku = array();
     $total = array();
     $quantity = array();
     $unit = array();
     foreach ($products as $item) {
         $code[] = $this->getCategoryArray($item);
         if (!empty($item->description)) {
             $desc = $item->description;
         } else {
             $desc = $item->title;
         }
         $desc = strip_tags($desc);
         $desc = TodoPago\Sdk::sanitizeValue($desc);
         $desc = substr($desc, 0, 50);
         $description[] = $desc;
         $name[] = substr($item->title, 0, 250);
         $sku[] = substr(empty($item->sku) ? $item->product_id : $item->sku, 0, 250);
         $total[] = number_format(commerce_currency_amount_to_decimal($item->commerce_price[LANGUAGE_NONE][0]["amount"], $item->commerce_price[LANGUAGE_NONE][0]["currency_code"]) * $cant_prod[$item->product_id], 2, ".", "");
         $quantity[] = $cant_prod[$item->product_id];
         $unit[] = number_format(commerce_currency_amount_to_decimal($item->commerce_price[LANGUAGE_NONE][0]["amount"], $item->commerce_price[LANGUAGE_NONE][0]["currency_code"]), 2, ".", "");
     }
     $productsData = array('CSITPRODUCTCODE' => join("#", $code), 'CSITPRODUCTDESCRIPTION' => join("#", $description), 'CSITPRODUCTNAME' => join("#", $name), 'CSITPRODUCTSKU' => join("#", $sku), 'CSITTOTALAMOUNT' => join("#", $total), 'CSITQUANTITY' => join("#", $quantity), 'CSITUNITPRICE' => join("#", $unit));
     return $productsData;
 }
 public function generatePaymentToken($order, $payment_method)
 {
     global $user;
     $config = array();
     $shippingAddressConfig = null;
     $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
     $billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value();
     $order_array = $order_wrapper->commerce_order_total->value();
     $product_line_items = $order->commerce_line_items[LANGUAGE_NONE];
     if (isset($order)) {
         $orderId = $order->order_id;
         $default_currency = commerce_default_currency();
         $amountCents = number_format(commerce_currency_convert($order->commerce_order_total['und'][0]['amount'], $order_array['currency_code'], $default_currency), 0, '', '');
         $scretKey = $payment_method['settings']['private_key'];
         $mode = $payment_method['settings']['mode'];
         $timeout = $payment_method['settings']['timeout'];
         $config['authorization'] = $scretKey;
         $config['mode'] = $mode;
         $config['timeout'] = $timeout;
         if ($payment_method['settings']['payment_action'] == 'authorize') {
             $config = array_merge($config, $this->_authorizeConfig());
         } else {
             $config = array_merge($config, $this->_captureConfig($payment_method));
         }
         $products = array();
         if (!empty($product_line_items)) {
             foreach ($product_line_items as $key => $item) {
                 $line_item[$key] = commerce_line_item_load($item['line_item_id']);
                 $product_id = $line_item[$key]->commerce_product['und'][0]['product_id'];
                 $product = commerce_product_load($product_id);
                 $price = commerce_product_calculate_sell_price($product);
                 $sell_price = number_format(commerce_currency_amount_to_decimal($price['amount'], $price['currency_code']), 2, '.', '');
                 $products[$key] = array('name' => commerce_line_item_title($line_item[$key]), 'sku' => $line_item[$key]->line_item_label, 'price' => $sell_price, 'quantity' => (int) $line_item[$key]->quantity);
             }
         }
         $billingAddressConfig = array('addressLine1' => $billing_address['thoroughfare'], 'addressLine2' => $billing_address['premise'], 'postcode' => $billing_address['postal_code'], 'country' => $billing_address['country'], 'city' => $billing_address['locality']);
         if (module_exists('commerce_shipping') && !empty($order_wrapper->commerce_customer_shipping->commerce_customer_address)) {
             $shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value();
             // Add the shipping address parameters to the request.
             $shippingAddressConfig = array('addressLine1' => $shipping_address['thoroughfare'], 'addressLine2' => $shipping_address['premise'], 'postcode' => $shipping_address['postal_code'], 'country' => $shipping_address['country'], 'city' => $shipping_address['locality']);
         }
         $config['postedParam'] = array_merge($config['postedParam'], array('email' => $order->mail, 'value' => $amountCents, 'trackId' => $orderId, 'currency' => $default_currency, 'description' => 'Order number::' . $orderId, 'shippingDetails' => $shippingAddressConfig, 'products' => $products, 'card' => array('billingDetails' => $billingAddressConfig)));
         $Api = CheckoutApi_Api::getApi(array('mode' => $mode));
         $paymentTokenCharge = $Api->getPaymentToken($config);
         $paymentTokenArray = array('message' => '', 'success' => '', 'eventId' => '', 'token' => '');
         if ($paymentTokenCharge->isValid()) {
             $paymentTokenArray['token'] = $paymentTokenCharge->getId();
             $paymentTokenArray['success'] = true;
         } else {
             $paymentTokenArray['message'] = $paymentTokenCharge->getExceptionState()->getErrorMessage();
             $paymentTokenArray['success'] = false;
             $paymentTokenArray['eventId'] = $paymentTokenCharge->getEventId();
         }
     }
     return $paymentTokenArray;
 }
 public function submitFormCharge($payment_method, $pane_form, $pane_values, $order, $charge)
 {
     $config = array();
     $shipping_array = array();
     $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
     $billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value();
     $order_array = $order_wrapper->commerce_order_total->value();
     $default_currency = commerce_default_currency();
     $amountCents = number_format(commerce_currency_convert($charge['amount'], $order_array['currency_code'], $default_currency), 0, '', '');
     $config['authorization'] = $payment_method['settings']['private_key'];
     $config['mode'] = $payment_method['settings']['mode'];
     $currency_code = $order_array['currency_code'];
     $i = 0;
     $config['postedParam'] = array('email' => $order->mail, 'value' => $amountCents, 'currency' => $default_currency, 'trackId' => $order->order_id, 'card' => array('name' => "{$billing_address['first_name']} {$billing_address['last_name']}", 'billingDetails' => array('addressLine1' => $billing_address['thoroughfare'], 'addressLine2' => $billing_address['premise'], 'postcode' => $billing_address['postal_code'], 'country' => $billing_address['country'], 'city' => $billing_address['locality'])));
     $products = null;
     foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
         $product_id = $line_item_wrapper->commerce_product->raw();
         $product = commerce_product_load($product_id);
         $price = commerce_product_calculate_sell_price($product);
         $sell_price = number_format(commerce_currency_amount_to_decimal($price['amount'], $price['currency_code']), 2, '.', '');
         // Add the line item to the return array.
         $products[$i] = array('productName' => commerce_line_item_title($line_item_wrapper->value()), 'price' => $sell_price, 'quantity' => round($line_item_wrapper->quantity->value()), 'sku' => '');
         // If it was a product line item, add the SKU.
         if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
             $products[$i]['sku'] = $line_item_wrapper->line_item_label->value();
         }
         $i++;
     }
     if ($products && !empty($products)) {
         $config['postedParam']['products'] = $products;
     }
     if (module_exists('commerce_shipping') && !empty($order_wrapper->commerce_customer_shipping->commerce_customer_address)) {
         $shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value();
         // Add the shipping address parameters to the request.
         $shipping_array = array('addressLine1' => $shipping_address['thoroughfare'], 'addressLine2' => $shipping_address['premise'], 'postcode' => $shipping_address['postal_code'], 'country' => $shipping_address['country'], 'city' => $shipping_address['locality']);
         $config['postedParam']['shippingDetails'] = $shipping_array;
     }
     if ($payment_method['settings']['payment_action'] == COMMERCE_CREDIT_AUTH_CAPTURE) {
         $config = array_merge_recursive($this->_captureConfig($payment_method), $config);
     } else {
         $config = array_merge_recursive($this->_authorizeConfig($payment_method), $config);
     }
     return $config;
 }
/**
 * Allows modules to alter defined Alipay API transaction parameters.
 *
 * The Commerce Alipay module defines by default the necessary properties to
 * provide support for the "Direct Pay" Alipay service type.
 * However, Alipay provides other types of services which may require different
 * properties and parameters to be passed when redirecting users for payment.
 * This hook allows other modules to alter these parameters to support other
 * service types, such as "DualFun", by providing additional keyed properties
 * as requested by the Alipay API.
 *
 * A few examples of the possible parameters that could be used along with this
 * hook are described in the implementation example below.
 * For more complete information on the Alipay API, please see:
 * http://club.alipay.com/read-htm-tid-9976972.html
 *
 * @param array $data
 *   An array of keyed properties to be passed to Alipay's payment gateway, in
 *   compliance with its API. Some of the possible keyed properties have been
 *   described in the implementation example below. To disable extensions or
 *   any key of the array, unset it or assign the parameter to null.
 * @param array $settings
 *   An array of the current settings configured for the payment method.
 * @param stdClass $order
 *   If available, the order object for which the payment should be processed.
 *
 * @see commerce_alipay_redirect_form()
 */
function hook_commerce_alipay_parameter_alter(&$data, $settings, $order)
{
    switch ($data['service']) {
        // Payment service: Direct Pay (Instant Payment Interface).
        case 'create_direct_pay_by_user':
            $data = array('partner' => 'ExamplePartnerID', 'payment_type' => '1', 'notify_url' => 'http://www.example.com/commerce_alipay/notify', 'return_url' => 'http://www.example.com/create_direct_pay_by_user-PHP-UTF-8/return_url.php', 'seller_email' => '*****@*****.**', 'out_trade_no' => 1357884681, 'subject' => 'Order number 1357884681', 'total_fee' => 1234, 'body' => 'Item example 1234', 'show_url' => 'http://www.example.com/myorder.html', 'anti_phishing_key' => query_timestamp(), 'exter_invoke_ip' => '221.0.0.1', '_input_charset' => 'UTF-8');
            break;
            // Payment service: Escrow Pay (Secured Transactions Interface).
        // Payment service: Escrow Pay (Secured Transactions Interface).
        case 'create_partner_trade_by_buyer':
            // Payment service: DualFun (Instant Payment and Secured Transactions).
        // Payment service: DualFun (Instant Payment and Secured Transactions).
        case 'trade_create_by_buyer':
            // The PartnerID is a string/key provided by Alipay to use its API.
            $data['partner'] = 'ExamplePartnerID';
            // Payment type is required.
            $data['payment_type'] = '1';
            // Server asynchronous notification page path, required. This is
            // supposed to be the URL where Alipay's callback notifications should
            // be received. It should start with http://, without custom parameters
            // such as ?id+123.
            $data['notify_url'] = 'http://www.example.com/commerce_alipay/notify';
            // Asynchronous redirection notification page path, required. It should
            // start with http://, not http://localhost/, without custom parameters
            // such as ?id+123.
            $data['return_url'] = 'http://www.example.com/create_partner_trade_by_buyer-PHP-UTF-8/return_url.php';
            // Alipay account seller's email, required.
            $data['seller_email'] = '*****@*****.**';
            // Merchant unique order number, required.
            $data['out_trade_no'] = 1357884681;
            // Order title, required.
            $data['subject'] = 'Order number 1357884681';
            // Total fee, amount to be paid, required.
            $data['price'] = 100;
            // Product quantity, required. It is recommended to set the default value
            // to 1 to consider a transaction as an order rather than a product.
            $data['quantity'] = 1;
            // Logistics fee or shipping fee, required.
            $data['logistics_fee'] = 5.75;
            // Logistics type, required. Alternatives are EXPRESS, POST and EMS.
            $data['logistics_type'] = 'EXPRESS';
            // Order description: text displayed on Alipay's payment page.
            $data['body'] = 'Item example 1234';
            // Order URL, starting with http://,
            // for example http://www.www.com/myorder.html.
            $data['show_url'] = 'http://www.example.com/myorder.html';
            // Logistics payment, required. Alternatives are SELLER_PAY (paid by
            // sellers) and BUYER_PAY (paid by buyers).
            $data['logistics_payment'] = 'SELLER_PAY';
            // Receiver's name.
            $data['receive_name'] = 'Example Name';
            // Receiver's full address, including information about province, city,
            // district, road, building, room, etc...
            $data['receive_address'] = 'XX省XXX市XXX区XXX路XXX小区XXX栋XXX单元XXX号';
            // Receiver's Postal Code.
            $data['receive_zip'] = '123456';
            // Receiver's telephone number.
            $data['receive_phone'] = '0571-XXXXXXXX';
            // Receiver's mobile phone number.
            $data['receive_mobile'] = '131XXXXXXXX';
            break;
            // Payment service: SendConfirm (Delivery confirmed Interface).
        // Payment service: SendConfirm (Delivery confirmed Interface).
        case 'send_goods_confirm_by_platform':
            // Alipay trade number, required.
            $data['trade_no'] = '1357884681';
            // Alipay trade number, required.
            $data['logistics_name'] = 'Example Provider Name';
            // Invoice number.
            $data['invoice_no'] = '1357884681';
            // Transportation type. Alternatives are POST, EXPRESS and EMS.
            $data['transport_type'] = 'POST';
            break;
            // Default configuration from commerce_alipay_redirect_form.
        // Default configuration from commerce_alipay_redirect_form.
        default:
            $data = array('service' => $settings['service'], 'payment_type' => '1', 'partner' => $settings['partner'], 'seller_email' => $settings['seller_email'], 'return_url' => $settings['return'], 'notify_url' => $settings['notify'], '_input_charset' => 'UTF-8', 'show_url' => $settings['return'], 'out_trade_no' => $order->order_number, 'subject' => t('order !order_id', array('!order_id' => $order->order_number)), 'body' => t('order !order_id', array('!order_id' => $order->order_number)), 'total_fee' => commerce_currency_amount_to_decimal($amount, 'CNY'), 'sign_type' => 'MD5');
            break;
    }
}
 /**
  * Returns a payment form to be used during checkout or elsewhere
  */
 public function paymentForm($form, &$form_state, &$request_state = array())
 {
     if (!$this->isValid()) {
         return $form;
     }
     // Resolve state
     $this->controller->resolvePaymentState($request_state);
     // Get plugin settings
     $settings = $this->getSettings();
     // Set transaction type based on settings.
     $txn_type = $this->controller->getSettings('txn_type');
     $x_type = 'AUTH_CAPTURE';
     if ($txn_type == COMMERCE_CREDIT_AUTH_ONLY) {
         $x_type = 'AUTH_ONLY';
     }
     // Initialize variables
     $order = $request_state['order'];
     $description = array();
     $card = $request_state['card'];
     $charge = $request_state['charge'];
     $cancel_path = '';
     // Order data
     if (!empty($order)) {
         $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
         $cancel_path = 'checkout/' . $order->order_id . '/payment/back/' . $order->data['payment_redirect_key'];
         // Build a description for the order.
         /** @todo: create details for x_line_item instead of x_description which is not used ***/
         foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
             if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
                 $description[] = round($line_item_wrapper->quantity->value(), 2) . 'x ' . $line_item_wrapper->line_item_label->value();
             }
         }
     }
     // Card data
     if (!empty($card)) {
         if (empty($cancel_path) && !empty($card->uid)) {
             $cancel_path = 'user/' . $card->uid . '/cards';
         }
     }
     // Resolve charge - convert to decimal, fallback to 0
     if (!empty($charge['amount'])) {
         $charge['amount_decimal'] = commerce_currency_amount_to_decimal($charge['amount'], $charge['currency_code']);
     } else {
         // Fallback to Zero dollar authorization
         $x_type = 'AUTH_ONLY';
         $charge = array('amount' => 0, 'amount_decimal' => 0, 'currency_code' => isset($charge['currency_code']) ? $charge['currency_code'] : commerce_default_currency());
     }
     // Build submit data
     $data = array('x_login' => $settings['page_id'], 'x_type' => $x_type, 'x_amount' => !empty($charge['amount_decimal']) ? number_format($charge['amount_decimal'], 2, '.', '') : '0', 'x_currency_code' => $charge['currency_code'], 'x_show_form' => 'PAYMENT_FORM', 'x_customer_ip' => ip_address(), 'x_receipt_link_method' => 'AUTO-POST', 'x_receipt_link_url' => $this->getAutoPostURL(), 'x_relay_response' => 'TRUE', 'x_relay_url' => $this->getRelayURL(), 'commerce_payment_method' => $this->controller->payment_instance['instance_id']);
     // Conditional fields
     // Order info
     if (!empty($order->order_id)) {
         $data += array('commerce_order_id' => $order->order_id, 'x_invoice_num' => $order->order_number, 'x_description' => substr(implode(', ', $description), 0, 255));
     }
     // Customer
     if (!empty($request_state['customer']->uid)) {
         $data['x_cust_id'] = substr($request_state['customer']->uid, 0, 20);
         // Set customer_ref similar to web service
         // - x_po_num is passed to customer_ref in response
         $data['x_po_num'] = $data['x_cust_id'];
     }
     if (!empty($request_state['customer']->mail)) {
         $data['x_email'] = substr($request_state['customer']->mail, 0, 255);
     }
     // Billing address
     if (!empty($request_state['billing_address'])) {
         $billing_address = $request_state['billing_address'];
         $data += array('x_first_name' => substr($billing_address['first_name'], 0, 50), 'x_last_name' => substr($billing_address['last_name'], 0, 50), 'x_company' => substr($billing_address['organisation_name'], 0, 20), 'x_address' => substr($billing_address['street_line'], 0, 28), 'x_city' => substr($billing_address['locality'], 0, 20), 'x_state' => $this->controller->getStateName($billing_address['administrative_area'], $billing_address['country']), 'x_zip' => substr($billing_address['postal_code'], 0, 9), 'x_country' => $this->controller->getCountryName($billing_address['country']));
     }
     // Allow other plugins and modules to alter
     $this->controller->alter('hpp_post_data', $data, $request_state);
     // Create the hash fingerprint
     $hmac_encryption_type = !empty($settings['hmac_encryption_type']) ? $settings['hmac_encryption_type'] : 'md5';
     $data['x_fp_timestamp'] = REQUEST_TIME;
     $data['x_fp_sequence'] = mt_rand(1, 1000);
     $hash_seeds = array($data['x_login'], $data['x_fp_sequence'], $data['x_fp_timestamp'], $data['x_amount'], $data['x_currency_code']);
     $data['x_fp_hash'] = hash_hmac($hmac_encryption_type, implode('^', $hash_seeds), $settings['transaction_key']);
     // Log "request"
     $log_settings = $this->controller->getSettings('log');
     if ($log_settings['request'] == 'request') {
         $this->controller->log('First Data GGe4 HPP submit data', $data);
     }
     // Set post url and transaction mode
     $submit_url = $this->getServerUrl();
     $data['x_test_request'] = $this->isTestMode() ? 'TRUE' : 'FALSE';
     // Build form elements
     $form['#action'] = $submit_url;
     $form['#method'] = "post";
     foreach ($data as $name => $value) {
         $form[$name] = array('#type' => 'hidden', '#value' => $value);
     }
     $form['actions'] = array('#type' => 'actions', '#weight' => 50);
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Continue'));
     $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => $cancel_path, '#options' => array('absolute' => TRUE, 'html' => FALSE));
     // Allow other plugins and modules to alter
     $this->controller->alter('hpp_payment_form', $form, $request_state);
     return $form;
 }
 /**
  * Web Service: Build JSON request parameters
  *
  * Assumes request has been validated.
  *
  * @param $request_state
  *   @see CommerceFirstDataGGE4Controller::resolvePaymentState()
  *
  * @return
  *   A name-value pair array for a JSON request
  */
 protected function requestBuild(&$request_state)
 {
     // Resolve state
     $this->controller->resolvePaymentState($request_state);
     // Set local vars for easy reference
     $charge = $request_state['charge'];
     $card = $request_state['card'];
     $order = $request_state['order'];
     $billing_address = $request_state['billing_address'];
     $prev_transaction = $request_state['previous_transaction'];
     // load transaction type info
     $txn_type_info = $this->controller->transactionType($request_state['txn_type']);
     // Add build info with request indicators
     $request_state['build_info'] = array('zero_amount' => commerce_firstdata_gge4_is_zero($charge['amount']));
     // Zero Dollar Pre-Authorizations
     if ($request_state['txn_type'] != FIRSTDATA_GGE4_CREDIT_PREAUTH_ONLY && $request_state['build_info']['zero_amount'] && !empty($txn_type_info['zero_auth_allowed'])) {
         $request_state['txn_type'] = FIRSTDATA_GGE4_CREDIT_PREAUTH_ONLY;
         $txn_type_info = $this->controller->transactionType($request_state['txn_type']);
     }
     // Convert Commerce txn type to gateway code
     $request_state['gateway_txn_type'] = $txn_type_info['gateway_code'];
     // Set transaction type
     $txn_type_code = $request_state['txn_type'];
     // Initialize request parameters
     $params = array('transaction_type' => $request_state['gateway_txn_type']);
     // Determine charge context
     $params += array('amount' => !$request_state['build_info']['zero_amount'] ? commerce_currency_amount_to_decimal($charge['amount'], $charge['currency_code']) : 0, 'currency_code' => $charge['currency_code']);
     // Parameters required per txn type
     if (!empty($txn_type_info['requires_card'])) {
         // Purchase, Pre-auth, Pre-auth only, Refund via credit card
         // Billing address parameters
         if (!empty($billing_address)) {
             $params['zip_code'] = substr($billing_address['postal_code'], 0, 10);
             // cc_verification_str1: "Street Address|Zip/Postal|City|State/Prov|Country"
             $billing_address_verify_parts = array($billing_address['street_line'], $billing_address['postal_code'], $billing_address['locality'], $billing_address['administrative_area'], $billing_address['country']);
             $params['cc_verification_str1'] = implode('|', $billing_address_verify_parts);
             $params['cc_verification_str1'] = substr($params['cc_verification_str1'], 0, 41);
         }
         // Add expiration
         $params += array('cc_expiry' => str_pad($card->card_exp_month, 2, '0', STR_PAD_LEFT) . substr($card->card_exp_year, -2));
         // Add cardholder name
         $cardholder_name = '';
         if (!empty($card->card_name)) {
             // Set to name on card
             $cardholder_name = $card->card_name;
         } elseif (!empty($billing_address['name_line'])) {
             // Set to billing address name
             $cardholder_name = $billing_address['name_line'];
         }
         $card->card_name = $params['cardholder_name'] = substr($cardholder_name, 0, 30);
         // Add additional card data
         $params += array('cc_number' => substr($card->card_number, 0, 16));
         // CVV code should only be available during checkout or new cards
         if (!empty($card->card_code)) {
             $params['cc_verification_str2'] = substr($card->card_code, 0, 4);
             $params['cvd_presence_ind'] = "1";
         }
     } elseif (!empty($txn_type_info['transaction_operation'])) {
         // Pre-auth capture, Void, Refund
         $params['authorization_num'] = substr($prev_transaction->data['authorization_num'], 0, 8);
         $params['transaction_tag'] = (int) $prev_transaction->data['transaction_tag'];
     }
     // Add order information
     if (!empty($order->order_number)) {
         $params['reference_no'] = $order->order_number;
     }
     // @todo: Level 2 order info - tax, etc
     // @todo: Level 3 order info - line items, etc
     // Add customer params
     if (isset($request_state['customer']->uid)) {
         $params['customer_ref'] = substr($request_state['customer']->uid, 0, 20);
     }
     if (isset($request_state['customer']->mail)) {
         $params['client_email'] = substr($request_state['customer']->mail, 0, 255);
     }
     $params['client_ip'] = substr(ip_address(), 0, 15);
     // Common parameters
     /** @todo use site or get from owner - order or card **/
     $params['language'] = $this->controller->convertLanguage(language_default('language'));
     // Allow other plugins and modules to alter
     $this->controller->alter('ws_request_build', $params, $request_state);
     return $params;
 }
Esempio n. 7
0
 /**
  * Perform a Contract Charges query call to Amazon API.
  *
  * @param commerce_order $order
  * @internal param $action
  * @return bool|object
  */
 public function setContractCharges($order)
 {
     $params = $this->constructParams('SetContractCharges');
     $discount_amount = $shipping_amount = $tax_amount = 0;
     $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
     $total_price = commerce_price_wrapper_value($order_wrapper, 'commerce_order_total');
     $tax_amount = commerce_tax_total_amount($total_price['data']['components'], FALSE, $total_price['currency_code']);
     foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
         if (!in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
             // Shipping line items.
             if ($line_item_wrapper->type->value() == 'shipping') {
                 $shipping_amount += $line_item_wrapper->commerce_total->amount->value();
                 $shipping_currency_code = $line_item_wrapper->commerce_total->currency_code->value();
             }
             // We assume that a negative amount is a discount or similar.
             if ($line_item_wrapper->commerce_total->amount->value() < 0) {
                 $discount_amount += $line_item_wrapper->commerce_total->amount->value();
                 $discount_currency_code = $line_item_wrapper->commerce_total->currency_code->value();
             }
         }
     }
     // Providing taxes and shipping information, even if it's 0.
     $params['Charges.Tax.Amount'] = commerce_currency_amount_to_decimal($tax_amount, $total_price['currency_code']);
     $params['Charges.Tax.CurrencyCode'] = $total_price['currency_code'];
     $shipping_currency_code = !empty($shipping_currency_code) ? $shipping_currency_code : $total_price['currency_code'];
     $params['Charges.Shipping.Amount'] = commerce_currency_amount_to_decimal($shipping_amount, $shipping_currency_code);
     $params['Charges.Shipping.CurrencyCode'] = $shipping_currency_code;
     if ($discount_amount != 0) {
         $params['Charges.Promotions.Promotion.1.PromotionId'] = t('Discount');
         $params['Charges.Promotions.Promotion.1.Description'] = t('Discount');
         $params['Charges.Promotions.Promotion.1.Discount.Amount'] = abs(commerce_currency_amount_to_decimal($discount_amount, $discount_currency_code));
         $params['Charges.Promotions.Promotion.1.Discount.CurrencyCode'] = $discount_currency_code;
     }
     // Allow other modules to alter the params on demand.
     drupal_alter('commerce_cba_contract_charges', $params, $order);
     if (!empty($params)) {
         $query = $this->prepareQuery($params);
         return $this->query($query);
     }
 }
function get_paydata($order, $user, $form, $payment_method)
{
    $vertical = $payment_method["settings"]["general"]["segmento"];
    switch ($vertical) {
        case "Retail":
            $vertical = ControlFraudeFactory::RETAIL;
            break;
        case "Ticketing":
            $vertical = ControlFraudeFactory::TICKETING;
            break;
        case "Services":
            $vertical = ControlFraudeFactory::SERVICE;
            break;
        case "Digital_Goods":
            $vertical = ControlFraudeFactory::DIGITAL_GOODS;
            break;
    }
    $dataFraude = ControlFraudeFactory::get_controlfraude_extractor($vertical, $user, $order)->getDataCS();
    $form = array_merge($form, $dataFraude);
    foreach ($form as $key => $value) {
        $optionsSAR_operacion[$key] = $value["#value"];
    }
    $monto = commerce_currency_amount_to_decimal($order->commerce_order_total[LANGUAGE_NONE][0]["amount"], $order->commerce_order_total[LANGUAGE_NONE][0]["currency_code"]);
    $settings = $payment_method["settings"];
    if ($settings["general"]["modo"] == "Produccion") {
        $modo = "ambienteproduccion";
    } else {
        $modo = "ambientetest";
    }
    $optionsSAR_comercio = array('Security' => $settings[$modo]["security"], 'EncodingMethod' => 'XML', 'Merchant' => $settings[$modo]["idsite"], 'URL_OK' => url('commerce/todopago/notification/' . $order->order_id . "/" . $order->data['payment_redirect_key'], array('absolute' => TRUE)), 'URL_ERROR' => url('commerce/todopago/notification/' . $order->order_id . "/" . $order->data['payment_redirect_key'], array('absolute' => TRUE)));
    $optionsSAR_operacion["MERCHANT"] = $settings[$modo]["idsite"];
    $optionsSAR_operacion["OPERATIONID"] = $order->order_id;
    $optionsSAR_operacion["CURRENCYCODE"] = 032;
    $optionsSAR_operacion["AMOUNT"] = $monto;
    //creo el conector con el valor de Authorization, la direccion de WSDL y endpoint que corresponda
    $connector = get_connector($settings);
    return array($connector, $optionsSAR_comercio, $optionsSAR_operacion);
}