本文整理汇总了PHP中WC_Order::get_total方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order::get_total方法的具体用法?PHP WC_Order::get_total怎么用?PHP WC_Order::get_total使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Order
的用法示例。
在下文中一共展示了WC_Order::get_total方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_total
/**
* Get the total amount with or without refunds
* @return string
*/
public function get_total()
{
$total = '';
if ($this->order->get_total_refunded() > 0) {
$total_after_refund = $this->order->get_total() - $this->order->get_total_refunded();
$total = '<del class="total-without-refund">' . strip_tags($this->order->get_formatted_order_total()) . '</del> <ins>' . wc_price($total_after_refund, array('currency' => $this->order->get_order_currency())) . '</ins>';
} else {
$total = $this->order->get_formatted_order_total();
}
return $total;
}
示例2: output_order_tracking_code
/**
* Output the order tracking code for enabled networks
*
* @param int $order_id
*
* @return string
*/
public function output_order_tracking_code($order_id)
{
$order = new WC_Order($order_id);
$code = "<script>fbq('track', 'Purchase', {value: '" . esc_js($order->get_total()) . "', currency: '" . esc_js($order->get_order_currency()) . "'});</script>";
$code .= '<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=' . esc_js($this->facebook_id) . '&ev=Purchase&cd[value]=' . urlencode($order->get_total()) . '&cd[currency]=' . urlencode($order->get_order_currency()) . '&noscript=1"
/></noscript>';
echo $code;
}
开发者ID:bitpiston,项目名称:woocommerce-facebook-remarketing,代码行数:16,代码来源:class-wc-facebook-remarketing-integration.php
示例3: array
/**
* Track custom user properties via the Mixpanel API
*
* This example illustrates how to add/update the "Last Subscription Billing Amount"
* user property when a subscription is renewed.
*
* @param \WC_Order $renewal_order
* @param \WC_Order $original_order
* @param int $product_id the
* @param \WC_Order $new_order_role
*/
function sv_wc_mixpanel_renewed_subscription($renewal_order, $original_order, $product_id, $new_order_role)
{
if (!function_exists('wc_mixpanel')) {
return;
}
$properties = array('Last Subscription Billing Amount' => $renewal_order->get_total());
wc_mixpanel()->get_integration()->custom_user_properties_api($properties, $renewal_order->user_id);
}
示例4: payfort_payment_fields
public function payfort_payment_fields($order_id)
{
$order = new WC_Order($order_id);
$argsArr = ['PSPID' => $this->payfort_production_mode ? $this->payfort_production_pspid : $this->payfort_test_pspid, 'AMOUNT' => $order->get_total() * 100, 'ORDERID' => $order->id, 'CURRENCY' => 'EGP', 'LANGUAGE' => 'en_US', 'CN' => $order->billing_first_name . ' ' . $order->billing_last_name, 'EMAIL' => $order->billing_email, 'OWNERZIP' => $order->billing_postcode, 'OWNERADDRESS' => $order->billing_address_1 . ',' . $order->billing_address_2, 'OWNERCTY' => $order->billing_country, 'OWNERTOWN' => $order->billing_city, 'OWNERTELNO' => $order->billing_phone, 'HOMEURL' => home_url(), 'TITLE' => $this->title, 'BGCOLOR' => $this->payfort_payment_page_bg_color, 'TXTCOLOR' => $this->payfort_payment_page_text_color, 'TBLBGCOLOR' => $this->payfort_payment_page_table_bg_color, 'TBLTXTCOLOR' => $this->payfort_payment_page_table_text_color, 'BUTTONBGCOLOR' => $this->payfort_payment_page_btn_bg_color, 'BUTTONTXTCOLOR' => $this->payfort_payment_page_btn_text_color, 'ACCEPTURL' => $this->payfort_accept_url, 'DECLINEURL' => $this->payfort_accept_url, 'EXCEPTIONURL' => $this->payfort_accept_url, 'CANCELURL' => $this->payfort_accept_url];
if (isset($this->payment_page_logo) && !empty($this->payfort_payment_page_logo)) {
$argsArr['LOGO'] = $this->payfort_payment_page_logo;
}
return $argsArr;
}
示例5: get_total
/**
* Returns the order total, in order currency.
*
* @since WooCommerce 2.1.
*/
public function get_total()
{
// If parent has this method, let's use it. It means we are in WooCommerce 2.1+
if (method_exists(get_parent_class($this), __FUNCTION__)) {
return parent::get_total();
}
// Fall back to legacy method in WooCommerce 2.0 and earlier
return $this->get_order_total();
}
示例6: process_payment
public function process_payment( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
//get payment tendered amount
$payment_amount = $_POST['payment_amount'];
//get order total
$order_total = $order->get_total();
//check for previous payments tendered and add to total payment
$tendered = get_post_meta( $order->id, 'payment_tendered', true );
$payment_amount = (float)$payment_amount + (float)$tendered;
//calculate balance after payment applied
$balance = $order_total - $payment_amount;
//if payment still needed
if( $balance > 0 ) {
//document transaction and create order note
update_post_meta( $order->id, 'payment_tendered', $payment_amount );
$order->add_order_note( __( '$ ' . round( $payment_amount, 2 ) . ' payment tendered. $ ' . round( $balance, 2 ) . ' remaining.', 'instore' ) );
$order->update_status('pending', __( 'Awaiting additional payment', 'instore' ) );
$payment_complete = false;
} else {
//resuce stock and add order note
$order->reduce_order_stock();
$order->add_order_note( __( '$ ' . round( $payment_amount, 2 ) . ' payment Tendered. Change Due $ ' . round( $balance, 2 ) . ' .', 'instore' ) );
//complete order
$order->payment_complete();
$payment_complete = true;
//empty cart
$woocommerce->cart->empty_cart();
};
//create return array
$results = array(
'result' => 'success',
'order_id' => $order_id,
'order_total' => $order_total,
'balance' => $balance,
'balance_formatted' => wc_price( -$balance ),
'payment_tendered' => wc_price( $payment_amount ),
'payment_complete' => $payment_complete,
);
//return results
return $results;
}
示例7: get_order_total
/**
* Get the order total in checkout and pay_for_order.
*
* @return bool
*/
protected function get_order_total()
{
$total = 0;
$order_id = absint(get_query_var('order-pay'));
// Gets order total from "pay for order" page.
if (0 < $order_id) {
$order = new WC_Order($order_id);
$total = (double) $order->get_total();
// Gets order total from cart/checkout.
} elseif (0 < WC()->cart->total) {
$total = (double) WC()->cart->total;
}
return $total;
}
示例8: explode
function successful_request($posted)
{
//print_r($posted);
global $woocommerce;
$order_id_key = $posted['customerReference'];
$order_id_key = explode("-", $order_id_key);
$order_id = $order_id_key[0];
$order_key = $order_id_key[1];
$responseCode = $posted['responseCode'];
$responseText = $posted['responseText'];
$txnreference = $posted['txnreference'];
$order = new WC_Order($order_id);
if ($order->order_key !== $order_key) {
echo 'Error: Order Key does not match invoice.';
exit;
}
if ($order->get_total() != $posted['amount']) {
echo 'Error: Amount not match.';
$order->update_status('on-hold', sprintf(__('Validation error: BrainTree amounts do not match (%s).', 'woocommerce'), $posted['amount']));
exit;
}
// if TXN is approved
if ($responseCode == "00" || $responseCode == "08" || $responseCode == "77") {
// Payment completed
$order->add_order_note(__('payment completed', 'woocommerce'));
// Mark order complete
$order->payment_complete();
// Empty cart and clear session
$woocommerce->cart->empty_cart();
// Redirect to thank you URL
wp_redirect($this->get_return_url($order));
exit;
} else {
// Change the status to pending / unpaid
$order->update_status('pending', __('Payment declined', 'woothemes'));
// Add a note with the IPG details on it
$order->add_order_note(__('Braintree payment Failed - TransactionReference: ' . $txnreference . " - ResponseCode: " . $responseCode, 'woocommerce'));
// FAILURE NOTE
// Add error for the customer when we return back to the cart
$woocommerce->add_error(__('TRANSACTION DECLINED: ', 'woothemes') . $posted['responseText'] . "<br/>Reference: " . $txnreference);
// Redirect back to the last step in the checkout process
wp_redirect($woocommerce->cart->get_checkout_url());
exit;
}
}
示例9: get_order_total
/**
* Get order total.
*
* @return float
*/
public function get_order_total()
{
global $woocommerce;
$order_total = 0;
if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) {
$order_id = absint(get_query_var('order-pay'));
} else {
$order_id = isset($_GET['order_id']) ? absint($_GET['order_id']) : 0;
}
// Gets order total from "pay for order" page.
if (0 < $order_id) {
$order = new WC_Order($order_id);
$order_total = (double) $order->get_total();
// Gets order total from cart/checkout.
} elseif (0 < $woocommerce->cart->total) {
$order_total = (double) $woocommerce->cart->total;
}
return $order_total;
}
示例10: confirm_url_callback
public function confirm_url_callback()
{
$transaction_id = $_GET['transactionId'];
$results = get_posts(array('post_type' => 'shop_order', 'meta_query' => array(array('key' => '_hpd_linepay_transactionId', 'value' => $transaction_id))));
if (!$results) {
http_response_code(404);
exit;
}
$order_data = $results[0];
$order_id = $order_data->ID;
$order = new WC_Order($order_id);
$response_data = $this->client->confirm($transaction_id, $order->get_total(), get_woocommerce_currency());
if ($response_data->returnCode != '0000') {
$order->update_status('failed', sprintf(__('Error return code: %1$s, message: %2$s', 'wc-payment-gateway-line-pay'), $response_data->returnCode, $response_data->returnMessage));
} else {
$order->payment_complete();
}
wp_redirect($order->get_checkout_order_received_url());
exit;
}
示例11: getRequestData
/**
* Bundle and format the order information
* @param WC_Order $order
* Send as much information about the order as possible to Conekta
*/
function getRequestData($order)
{
if ($order and $order != null) {
// custom fields
$custom_fields = array("total_discount" => (double) $order->get_total_discount() * 100);
// $user_id = $order->get_user_id();
// $is_paying_customer = false;
$order_coupons = $order->get_used_coupons();
// if ($user_id != 0) {
// $custom_fields = array_merge($custom_fields, array(
// "is_paying_customer" => is_paying_customer($user_id)
// ));
// }
if (count($order_coupons) > 0) {
$custom_fields = array_merge($custom_fields, array("coupon_code" => $order_coupons[0]));
}
return array("amount" => (double) $order->get_total() * 100, "token" => $_POST['conektaToken'], "shipping_method" => $order->get_shipping_method(), "shipping_carrier" => $order->get_shipping_method(), "shipping_cost" => (double) $order->get_total_shipping() * 100, "monthly_installments" => (int) $_POST['monthly_installments'], "currency" => strtolower(get_woocommerce_currency()), "description" => sprintf("Charge for %s", $order->billing_email), "card" => array_merge(array("name" => sprintf("%s %s", $order->billing_first_name, $order->billing_last_name), "address_line1" => $order->billing_address_1, "address_line2" => $order->billing_address_2, "billing_company" => $order->billing_company, "phone" => $order->billing_phone, "email" => $order->billing_email, "address_city" => $order->billing_city, "address_zip" => $order->billing_postcode, "address_state" => $order->billing_state, "address_country" => $order->billing_country, "shipping_address_line1" => $order->shipping_address_1, "shipping_address_line2" => $order->shipping_address_2, "shipping_phone" => $order->shipping_phone, "shipping_email" => $order->shipping_email, "shipping_address_city" => $order->shipping_city, "shipping_address_zip" => $order->shipping_postcode, "shipping_address_state" => $order->shipping_state, "shipping_address_country" => $order->shipping_country), $custom_fields));
}
return false;
}
示例12: dokan_sync_insert_order
/**
* Insert a order in sync table once a order is created
*
* @global object $wpdb
* @param int $order_id
*/
function dokan_sync_insert_order($order_id)
{
global $wpdb;
$order = new WC_Order($order_id);
$seller_id = dokan_get_seller_id_by_order($order_id);
$percentage = dokan_get_seller_percentage($seller_id);
$order_total = $order->get_total();
$order_status = $order->post_status;
$wpdb->insert($wpdb->prefix . 'dokan_orders', array('order_id' => $order_id, 'seller_id' => $seller_id, 'order_total' => $order_total, 'net_amount' => $order_total * $percentage / 100, 'order_status' => $order_status), array('%d', '%d', '%f', '%f', '%s'));
}
示例13: substr
function generate_alphabank_form($order_id)
{
global $wpdb;
$order = new WC_Order($order_id);
$merchantreference = substr(sha1(rand()), 0, 30);
if ($this->mode == "yes") {
//test mode
$post_url = 'https://alpha.test.modirum.com/vpos/shophandlermpi';
} else {
//live mode
$post_url = 'https://www.alphaecommerce.gr/vpos/shophandlermpi';
}
//Alpha.rand(0,99).date("YmdHms")
$form_data = "";
$form_data_array = array();
$form_mid = $this->alphabank_Merchant_ID;
$form_data_array[1] = $form_mid;
//Req
$form_lang = "el";
$form_data_array[2] = $form_lang;
//Opt
$form_device_cate = "";
$form_data_array[3] = $form_device_cate;
//Opt
$form_order_id = $order_id;
$form_data_array[4] = $form_order_id;
//Req
$form_order_desc = "";
$form_data_array[5] = $form_order_desc;
//Opt
$form_order_amount = $order->get_total();
$form_data_array[6] = $form_order_amount;
//Req
// $form_order_amount = 0.10; $form_data_array[6] = $form_order_amount; //Req
$form_currency = "EUR";
$form_data_array[7] = $form_currency;
//Req
$form_email = $order->billing_email;
$form_data_array[8] = $form_email;
//Req
$form_phone = "";
$form_data_array[9] = $form_phone;
//Opt
$form_bill_country = "";
$form_data_array[10] = $form_bill_country;
//Opt
$form_bill_state = "";
$form_data_array[11] = $form_bill_state;
//Opt
$form_bill_zip = "";
$form_data_array[12] = $form_bill_zip;
//Opt
$form_bill_city = "";
$form_data_array[13] = $form_bill_city;
//Opt
$form_bill_addr = "";
$form_data_array[14] = $form_bill_addr;
//Opt
$form_weight = "";
$form_data_array[15] = $form_weight;
//Opt
$form_dimension = "";
$form_data_array[16] = $form_dimension;
//Opt
$form_ship_counrty = "";
$form_data_array[17] = $form_ship_counrty;
//Opt
$form_ship_state = "";
$form_data_array[18] = $form_ship_state;
//Opt
$form_ship_zip = "";
$form_data_array[19] = $form_ship_zip;
//Opt
$form_ship_city = "";
$form_data_array[20] = $form_ship_city;
//Opt
$form_ship_addr = "";
$form_data_array[21] = $form_ship_addr;
//Opt
$form_add_fraud_score = "";
$form_data_array[22] = $form_add_fraud_score;
//Opt
$form_max_pay_retries = "";
$form_data_array[23] = $form_max_pay_retries;
//Opt
$form_reject3dsU = "";
$form_data_array[24] = $form_reject3dsU;
//Opt
$form_pay_method = "";
$form_data_array[25] = $form_pay_method;
//Opt
$form_trytpe = "";
$form_data_array[26] = $form_trytpe;
//Opt
$form_ext_install_offset = "";
$form_data_array[27] = $form_ext_install_offset;
//Opt
$form_ext_install_period = "";
$form_data_array[28] = $form_ext_install_period;
//Opt
//.........这里部分代码省略.........
开发者ID:eellak,项目名称:woocommerce-alphabank-payment-gateway,代码行数:101,代码来源:woocommerce-alphabank-payment-gateway.php
示例14: get_order_data
/**
* Get the order data for the given ID.
*
* @since 2.5.0
* @param WC_Order $order The order instance
* @return array
*/
protected function get_order_data($order)
{
$order_post = get_post($order->id);
$dp = wc_get_price_decimals();
$order_data = array('id' => $order->id, 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_order_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
// add line items
foreach ($order->get_items() as $item_id => $item) {
$product = $order->get_product_from_item($item);
$product_id = null;
$product_sku = null;
// Check if the product exists.
if (is_object($product)) {
$product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
$product_sku = $product->get_sku();
}
$meta = new WC_Order_Item_Meta($item, $product);
$item_meta = array();
foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
$item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
}
$order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
}
// Add shipping.
foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
$order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
}
// Add taxes.
foreach ($order->get_tax_totals() as $tax_code => $tax) {
$order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
}
// Add fees.
foreach ($order->get_fees() as $fee_item_id => $fee_item) {
$order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
}
// Add coupons.
foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
$order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
}
$order_data = apply_filters('woocommerce_cli_order_data', $order_data);
return $this->flatten_array($order_data);
}
示例15: array
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
function process_payment($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);
$token = $_POST['payfortToken'];
try {
if (empty($token)) {
$error_msg = __('Please make sure your card details have been entered correctly.', 'woocommerce');
throw new Start_Error($error_msg);
}
$charge_description = $order->id . ": WooCommerce charge for " . $order->billing_email;
$order_items = $order->get_items();
$order_items_array_full = array();
$user_info = wp_get_current_user();
$user_name = $user_info->user_login;
$udata = get_userdata($user_info->ID);
if (isset($udata->user_registered)) {
$registered_at = date(DATE_ISO8601, strtotime($udata->user_registered));
} else {
$registered_at = date(DATE_ISO8601, strtotime(date("Y-m-d H:i:s")));
}
foreach ($order_items as $key => $items) {
$itemClass = new WC_Product($items['product_id']);
$order_items_array['title'] = $items['name'];
$order_items_array['amount'] = round($itemClass->get_price(), 2) * $this->currency_multiplier[get_woocommerce_currency()];
$order_items_array['quantity'] = $items['qty'];
array_push($order_items_array_full, $order_items_array);
}
$billing_address = array("first_name" => $order->billing_first_name, "last_name" => $order->billing_last_name, "country" => $order->billing_country, "city" => $order->billing_city, "address_1" => $order->billing_address_1, "address_2" => $order->billing_address_2, "phone" => $order->billing_phone, "postcode" => $order->billing_postcode);
$shipping_address = array("first_name" => $order->shipping_first_name, "last_name" => $order->shipping_last_name, "country" => $order->shipping_country, "city" => $order->shipping_city, "address_1" => $order->shipping_address_1, "address_2" => $order->shipping_address_2, "phone" => $order->shipping_phone, "postcode" => $order->shipping_postcode);
$shopping_cart_array = array('user_name' => $user_name, 'registered_at' => $registered_at, 'items' => $order_items_array_full, 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
$charge_args = array('description' => $charge_description, 'card' => $token, 'currency' => strtoupper(get_woocommerce_currency()), 'email' => $order->billing_email, 'ip' => $_SERVER['REMOTE_ADDR'], 'amount' => $order->get_total() * $this->currency_multiplier[get_woocommerce_currency()], 'shopping_cart' => $shopping_cart_array, 'shipping_amount' => round($order->get_total_shipping(), 2) * $this->currency_multiplier[get_woocommerce_currency()], 'metadata' => array('reference_id' => $order_id));
if ($this->test_mode == 'yes') {
Start::setApiKey($this->test_secret_key);
} else {
Start::setApiKey($this->live_secret_key);
}
$start_plugin_data = get_file_data('wp-content/plugins/payfort/woocommerce-payfort.php', array('Version'), 'plugin');
$woo_plugin_data = get_file_data('wp-content/plugins/woocommerce/woocommerce.php', array('Version'), 'plugin');
$userAgent = 'WooCommerce ' . $woo_plugin_data['0'] . ' / Start Plugin ' . $start_plugin_data['0'];
Start::setUserAgent($userAgent);
$charge = Start_Charge::create($charge_args);
// No exceptions? Yaay, all done!
$order->payment_complete();
return array('result' => 'success', 'redirect' => $this->get_return_url($order));
} catch (Start_Error $e) {
// TODO: Can we get the extra params (so the error is more apparent)?
// e.g. Instead of "request params are invalid", we get
// "extras":{"amount":["minimum amount (in the smallest currency unit) is 185 for AED"]
$error_code = $e->getErrorCode();
if ($error_code === "card_declined") {
$message = __('Error: ', 'woothemes') . $e->getMessage() . " Please, try with another card";
} else {
$message = __('Error: ', 'woothemes') . $e->getMessage();
}
// If function should we use?
if (function_exists("wc_add_notice")) {
// Use the new version of the add_error method
wc_add_notice($message, 'error');
} else {
// Use the old version
$woocommerce->add_error($message);
}
// we raise 'update_checkout' event for javscript
// to remove card token
WC()->session->set('refresh_totals', true);
return array('result' => 'fail', 'redirect' => '');
}
}