function successful_request($posted) { $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks')); if (!empty($posted['f_code'])) { $order = new jigoshop_order((int) $posted['mer_txn']); if ($order->status !== 'completed') { switch ($posted['f_code']) { case 'Ok': $order->add_order_note(__('Atom Standard payment completed', 'jigoshop')); $order->payment_complete(); wp_safe_redirect(add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(jigoshop_get_page_id('thanks'))))); exit; // case '0' : // Pending // case '-2' : // Failed // $order->update_status('on-hold', sprintf(__('Atom payment failed (%s)', 'jigoshop'), strtolower($posted['status']) ) ); // break; // case '0' : // Pending // case '-2' : // Failed // $order->update_status('on-hold', sprintf(__('Atom payment failed (%s)', 'jigoshop'), strtolower($posted['status']) ) ); // break; case 'F': $order->update_status('cancelled', __('Atom payment cancelled', 'jigoshop')); break; default: $order->update_status('cancelled', __('Atom exception', 'jigoshop')); break; } } exit; } }
/** * Process pingback request */ function check_ipn_response() { if (isset($_GET['paymentwallListener']) && $_GET['paymentwallListener'] == 'paymentwall_IPN') { $this->init_paymentwall_configs(); $pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']); if ($pingback->validate()) { $order = new jigoshop_order($pingback->getProductId()); // Check order exist and payment method is paymentwall if ($order->id && $order->payment_method == $this->id) { $order->add_order_note(__('IPN payment completed', PW_JIGO_TEXT_DOMAIN)); if ($pingback->isDeliverable()) { // Call Delivery Confirmation API if ($this->delivery == 'yes') { // Delivery Confirmation $delivery = new Paymentwall_GenerericApiObject('delivery'); $response = $delivery->post($this->prepare_delivery_confirmation_data($order, $pingback->getReferenceId())); } $order->update_status('processing', __('Order approved! Transaction ID: #' . $pingback->getReferenceId(), PW_JIGO_TEXT_DOMAIN)); $order->payment_complete(); } elseif ($pingback->isCancelable()) { $order->update_status(PW_JIGO_ORDER_STATUS_CANCELED, __('Order canceled by Paymentwall!', PW_JIGO_TEXT_DOMAIN)); } echo PW_JIGO_DEFAULT_SUCCESS_PINGBACK_VALUE; // Paymentwall expects response to be OK, otherwise the pingback will be resent } else { echo __("Undefined order or Payment method is invalid!", PW_JIGO_TEXT_DOMAIN); } } else { echo $pingback->getErrorSummary(); } die; } }
/** * Update lead status of the specified payment * * @param string $payment */ public static function update_status(Pronamic_Pay_Payment $payment, $can_redirect = false) { $id = $payment->get_source_id(); $order = new jigoshop_order((int) $id); $data = new Pronamic_WP_Pay_Extensions_Jigoshop_PaymentData($order); $should_update = !in_array($order->status, array(Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_COMPLETED, Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_PROCESSING)); if ($should_update) { $url = $data->get_normal_return_url(); switch ($payment->status) { case Pronamic_WP_Pay_Statuses::CANCELLED: $order->update_status(Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_CANCELLED, __('iDEAL payment cancelled.', 'pronamic_ideal')); $url = $data->get_cancel_url(); break; case Pronamic_WP_Pay_Statuses::EXPIRED: // Jigoshop PayPal gateway uses 'on-hold' order status for an 'expired' payment // @see http://plugins.trac.wordpress.org/browser/jigoshop/tags/1.2.1/gateways/paypal.php#L430 $order->update_status(Pronamic_WP_Pay_Extensions_Jigoshop_Jigoshop::ORDER_STATUS_ON_HOLD, __('iDEAL payment expired.', 'pronamic_ideal')); break; case Pronamic_WP_Pay_Statuses::FAILURE: // Jigoshop PayPal gateway uses 'on-hold' order status for an 'failure' in the payment // @see http://plugins.trac.wordpress.org/browser/jigoshop/tags/1.2.1/gateways/paypal.php#L431 $order->update_status('failed', __('iDEAL payment failed.', 'pronamic_ideal')); break; case Pronamic_WP_Pay_Statuses::SUCCESS: // Payment completed $order->add_order_note(__('iDEAL payment completed.', 'pronamic_ideal')); $order->payment_complete(); $url = $data->get_success_url(); break; case Pronamic_WP_Pay_Statuses::OPEN: $order->add_order_note(__('iDEAL payment open.', 'pronamic_ideal')); break; default: $order->add_order_note(__('iDEAL payment unknown.', 'pronamic_ideal')); break; } if ($url && $can_redirect) { wp_redirect($url, 303); exit; } } }
/** * Successful Payment! **/ function successful_request( $posted ) { // Custom holds post ID if ( !empty($posted['txn_type']) && !empty($posted['invoice']) ) { $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money'); if (!in_array(strtolower($posted['txn_type']), $accepted_types)) exit; $order = new jigoshop_order( (int) $posted['custom'] ); if ($order->order_key!==$posted['invoice']) exit; // Sandbox fix if ($posted['test_ipn']==1 && $posted['payment_status']=='Pending') $posted['payment_status'] = 'completed'; if ($order->status !== 'completed') : // We are here so lets check status and do actions switch (strtolower($posted['payment_status'])) : case 'completed' : // Payment completed $order->add_order_note( __('IPN payment completed', 'jigoshop') ); $order->payment_complete(); break; case 'denied' : case 'expired' : case 'failed' : case 'voided' : // Hold order $order->update_status('on-hold', sprintf(__('Payment %s via IPN.', 'jigoshop'), strtolower(sanitize($posted['payment_status'])) ) ); break; default: // No action break; endswitch; endif; exit; } }
/** * Successful payment processing * * @param array $posted */ function successful_request($posted) { $posted = stripslashes_deep($posted); // 'custom' holds post ID (Order ID) if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) { $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment'); $order = new jigoshop_order((int) $posted['custom']); // Sandbox fix if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') { $posted['payment_status'] = 'completed'; } $merchant = $this->testmode == 'no' ? $this->email : $this->testemail; if ($order->status !== 'completed') { // We are here so lets check status and do actions switch (strtolower($posted['payment_status'])) { case 'completed': if (!in_array(strtolower($posted['txn_type']), $accepted_types)) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'jigoshop'), $posted['txn_type'], $posted['custom'])); exit; } if ($order->get_order_number() !== $posted['invoice']) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'jigoshop'), $posted['invoice'], $posted['custom'])); exit; } // Validate Amount if (number_format((double) $order->order_total, $this->decimals, '.', '') != $posted['mc_gross']) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'jigoshop'), $posted['mc_gross'])); exit; } if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'jigoshop'), $posted['business'])); exit; } if (!in_array($posted['mc_currency'], apply_filters('jigoshop_multi_currencies_available', array(Jigoshop_Base::get_options()->get('jigoshop_currency'))))) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'jigoshop'), $posted['mc_currency'])); exit; } $order->add_order_note(__('PayPal Standard payment completed', 'jigoshop')); $order->payment_complete(); jigoshop_log('PAYPAL: IPN payment completed for Order ID: ' . $posted['custom']); break; case 'denied': case 'expired': case 'failed': case 'voided': // Failed order $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'jigoshop'), strtolower($posted['payment_status']))); jigoshop_log("PAYPAL: failed order with status = " . strtolower($posted['payment_status']) . "for Order ID: " . $posted['custom']); break; case 'refunded': case 'reversed': case 'chargeback': jigoshop_log("PAYPAL: payment status type - '" . $posted['payment_status'] . "' - not supported for Order ID: " . $posted['custom']); break; } } exit; } else { jigoshop_log("PAYPAL: function 'successful_request' -- empty initial required values -- EXITING!\n'posted' values = " . print_r($posted, true)); } }
function check_ipn_response() { if (isset($_GET['paymentwallListener']) && $_GET['paymentwallListener'] == 'paymentwall_IPN') { $this->paymentwall_init(); unset($_GET['paymentwallListener']); $pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']); if ($pingback->validate()) { $productId = $pingback->getProduct()->getId(); $order = new jigoshop_order((int) $productId); if ($order->id) { if ($pingback->isDeliverable()) { $order->update_status('completed', __('Order completed!', 'jigoshop')); } else { if ($pingback->isCancelable()) { $order->update_status('canceled', __('Order canceled by Paymentwall!', 'jigoshop')); } } $order->add_order_note(__('IPN payment completed', 'jigoshop')); echo 'OK'; // Paymentwall expects response to be OK, otherwise the pingback will be resent } else { echo "Undefined order!"; } } else { echo $pingback->getErrorSummary(); } die; } }
/** * Process Response from WorldPay */ private function process_response($posted) { $installation_id = $this->get_post('instId'); $cartId = $this->get_post('cartId'); $transId = $this->get_post('transId'); $processed_transID = get_post_meta($cartId, '_worldpay_processed_transID', true); $amount = $this->get_post('amount'); $authAmount = $this->get_post('authAmount'); $authCurrency = $this->get_post('authCurrency'); $currency = $this->get_post('currency'); $shop_currency = Jigoshop_Base::get_options()->get('jigoshop_currency'); $testMode = $this->get_post('testMode'); $error = array(); $order = new jigoshop_order((int) $cartId); // Do all checks only if transaction was processed. switch ($this->get_post('transStatus')) { case 'Y': // If the currency is locked. if ($this->fixed_currency == 'yes') { // All currencies should be the same. if ($currency != $authCurrency || $authCurrency != $shop_currency || $currency != $shop_currency) { $error['Locked_Currency_Error'] = sprintf(__('The currency paid in was different than the one requested. Order #: %s. Currency paid in: %s, the amount paid: %s. You should investigate further.', 'jigoshop'), $order->id, $authCurrency, $authAmount); } // All amounts should be the same if ($order->order_total != $amount || $authAmount != $order->order_total || $authAmount != $amount) { $error['Locked_Amount_Error'] = sprintf(__('There were differences in the amounts received. Order #: %s. Submitted: %s, Paid: %s, Order Total: %s. You should investigate further.', 'jigoshop'), $order->id, $amount, $authAmount, $order->order_total); } } else { // If currency submitted to WorldPay is the same as your store one. // They should always be the same even if you accept multiple currency payments. if ($currency != $shop_currency) { $error['currency'] = sprintf(__('The currency submitted to WorldPay (%s) is different than the main currency of your shop (%s). You should investigate further.', 'jigoshop'), $currency, $shop_currency); } // If multi-currency is supported, at least the amount submitted to WorldPay should be the same as the order total. if ($order->order_total != $amount) { $error['amount'] = sprintf(__('The order total (%s) is different than the amount submitted to WorldPay (%s). You should investigate further.', 'jigoshop'), $order->order_total, $amount); } } // Check merchant. if ($installation_id != $this->installation_id) { $error['instId'] = sprintf(__('Order was paid to installation ID: %s, which is different than the Installation ID set in your shop: %s. You should investigate further.', 'jigoshop'), $installation_id, $this->installation_id); } if ($transId == $processed_transID) { $error['already_processed'] = sprintf(__('Payment with the same transaction ID (%s) was already processed for this order. You should investigate further.', 'jigoshop'), $transId); } if ($this->testmode == 'no' && $testMode > 0) { $error['testmode'] = sprintf(__('Your shop is in Live mode, but you received a Test mode transaction. You should investigate further.', 'jigoshop')); } if (empty($error) && $testMode == 0) { // Payment completed as live response $order->add_order_note(__('WorldPay payment completed. Transaction ID: ' . $transId, 'jigoshop')); update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID); $order->payment_complete(); $args = array('key' => $order->order_key, 'order' => $order->id); $redirect_url = add_query_arg($args, get_permalink(jigoshop_get_page_id('thanks'))); } elseif (empty($error) && $testMode > 0) { // Payment completed as test response $order->add_order_note(__('TESTMODE: WorldPay payment completed. Transaction ID: ' . $transId, 'jigoshop')); update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID); $order->payment_complete(); $args = array('key' => $order->order_key, 'order' => $order->id); $redirect_url = add_query_arg($args, get_permalink(jigoshop_get_page_id('thanks'))); } if (!empty($error) && $this->receive_err_log == 'yes') { $info = sprintf(__('Order #%s ', 'jigoshop'), $order->id); $this->email_worldpay_error_logs($error, $posted, $info); $redirect_url = get_permalink(jigoshop_get_page_id('checkout')); } break; case 'C': if ($testMode == 0) { // Payment was canceled live. $order->cancel_order(__('Order was canceled by customer at WorldPay.', 'jigoshop')); } if ($testMode > 0) { // Payment was canceled in test mode. $order->cancel_order(__('TESTMODE: Order was canceled by customer at WorldPay.', 'jigoshop')); } $redirect_url = $this->get_post('MC_cancel_return'); break; default: // No action $redirect_url = $this->get_post('MC_cancel_return'); break; } echo '<html><head><meta http-equiv="refresh" content="2;url=' . $redirect_url . '"></head><body><WPDISPLAY ITEM=banner></body></html>'; exit; }
/** * Successful Payment! **/ function successful_request($posted) { // Custom holds post ID if (!empty($posted['mb_transaction_id'])) { $order = new jigoshop_order((int) $posted['transaction_id']); if ($order->status !== 'completed') { // We are here so lets check status and do actions switch ($posted['status']) { case '2': // Processed $order->add_order_note(__('Skrill payment completed', 'jigoshop')); $order->payment_complete(); break; case '0': // Pending // Pending case '-2': // Failed $order->update_status('on-hold', sprintf(__('Skrill payment failed (%s)', 'jigoshop'), strtolower($posted['status']))); break; case '-1': // Cancelled $order->update_status('cancelled', __('Skrill payment cancelled', 'jigoshop')); break; default: $order->update_status('cancelled', __('Skrill exception', 'jigoshop')); break; } } exit; } }
function check_ipn_response() { $this->kaznachey_init(); $request_json = file_get_contents('php://input'); $request = json_decode($request_json, true); $request_sign = md5($request["ErrorCode"] . $request["OrderId"] . $request["MerchantInternalPaymentId"] . $request["MerchantInternalUserId"] . number_format($request["OrderSum"], 2, ".", "") . number_format($request["Sum"], 2, ".", "") . strtoupper($request["Currency"]) . $request["CustomMerchantInfo"] . strtoupper($this->merchnatSecretKey)); if ($request['SignatureEx'] == $request_sign) { $order = new jigoshop_order($request["MerchantInternalPaymentId"]); if ($order->id) { $order->add_order_note(__('Заказ оплачен. Платеж через www.kaznachey.ua', 'jigoshop')); $order->payment_complete(); } } }
function jigoshop_process_shop_order_meta($post_id) { $jigoshop_options = Jigoshop_Base::get_options(); $jigoshop_errors = array(); $order = new jigoshop_order($post_id); // Get old data + attributes $data = (array) maybe_unserialize(get_post_meta($post_id, 'order_data', true)); //Get old order items $old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true)); // Add/Replace data to array $customerDetails = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_euvatno', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_postcode', 'billing_country', 'billing_state', 'billing_email', 'billing_phone', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_country', 'shipping_state'); $order_fields = array('shipping_method', 'shipping_service', 'payment_method', 'order_subtotal', 'order_discount_subtotal', 'order_shipping', 'order_discount', 'order_discount_coupons', 'order_tax_total', 'order_shipping_tax', 'order_total', 'order_total_prices_per_tax_class_ex_tax'); /* Pre-fill the customer addresses */ foreach ($customerDetails as $key) { $order_fields[] = $key; /* Checks if this is a new order from "Add Order" button */ if (!empty($_POST['auto_draft']) && !empty($_POST['customer_user']) && empty($_POST[$key])) { $data[$key] = get_user_meta($_POST['customer_user'], $key, true); } } //Check EUVAT Field if (!empty($data['billing_euvatno']) && !empty($data['billing_country'])) { $data['billing_euvatno'] = str_replace(' ', '', $data['billing_euvatno']); } //run stripslashes on all valid fields foreach ($order_fields as $field_name) { if (isset($_POST[$field_name])) { $data[$field_name] = stripslashes($_POST[$field_name]); } } // Sanitize numeric values $data['order_total'] = jigoshop_sanitize_num($data['order_total']); $data['order_subtotal'] = jigoshop_sanitize_num($data['order_subtotal']); // if a shipping or payment methods has changed, update the method title for pretty display if (isset($_POST['shipping_method'])) { $data['shipping_service'] = ''; $shipping_methods = jigoshop_shipping::get_all_methods(); if (!empty($shipping_methods)) { foreach ($shipping_methods as $method) { if ($_POST['shipping_method'] == $method->id) { $data['shipping_service'] = $method->title; } } } } if (isset($_POST['payment_method'])) { $data['payment_method_title'] = ''; $payment_methods = jigoshop_payment_gateways::get_available_payment_gateways(); if (!empty($payment_methods)) { foreach ($payment_methods as $method) { if ($_POST['payment_method'] == $method->id) { $data['payment_method_title'] = $method->title; } } } } // if total tax has been modified from order tax, then create a customized tax array // just for the order. At this point, we no longer know about multiple tax classes. // Even if we used the old tax array data, we still don't know how to break down // the amounts since they're customized. if (isset($data['order_tax_total']) && $order->get_total_tax() != $data['order_tax_total']) { $new_tax = $data['order_tax_total']; $data['order_tax'] = jigoshop_tax::create_custom_tax($data['order_total'] - $data['order_tax_total'], $data['order_tax_total'], $data['order_shipping_tax'], isset($data['order_tax_divisor']) ? $data['order_tax_divisor'] : null); } // Customer update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']); // Order items $order_items = array(); if (isset($_POST['item_id'])) { $item_id = $_POST['item_id']; $item_variation = $_POST['item_variation_id']; $item_name = $_POST['item_name']; $item_quantity = $_POST['item_quantity']; $item_cost = $_POST['item_cost']; $item_tax_rate = $_POST['item_tax_rate']; for ($i = 0; $i < count($item_id); $i++) { if (!isset($item_id[$i]) || !isset($item_name[$i]) || !isset($item_quantity[$i]) || !isset($item_cost[$i]) || !isset($item_tax_rate[$i])) { continue; } $variation_id = ''; $variation = ''; if (!empty($item_variation[$i])) { $variation_id = (int) $item_variation[$i]; // if this is a variation, we should check if it is an old one // and copy the 'variation' field describing details of variation foreach ($old_order_items as $old_item_index => $old_item) { if ($old_item['variation_id'] == $variation_id) { $variation = $old_item['variation']; unset($old_order_items[$old_item_index]); break; } } // override variation with values from $_POST if (isset($_POST['order_attributes'][$i]) && is_array($_POST['order_attributes'][$i])) { foreach ($_POST['order_attributes'][$i] as $var_key => $var_value) { $variation[$var_key] = $var_value; } } } $cost_inc_tax = $jigoshop_options->get('jigoshop_prices_include_tax') == 'yes' ? number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', '') : -1; $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => $variation_id, 'variation' => $variation, 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'cost' => number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', ''), 'cost_inc_tax' => $cost_inc_tax, 'taxrate' => number_format((double) jigowatt_clean($item_tax_rate[$i]), 4, '.', ''))); } } // Process custom attributes added with "jigoshop_order_data_panels" $data = apply_filters("jigoshop_order_data_save", $data, $post_id); // Save update_post_meta($post_id, 'order_data', $data); update_post_meta($post_id, 'order_items', $order_items); // Order status $order->update_status($_POST['order_status']); // Handle button actions if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && count($order_items) > 0) { $order->add_order_note(__('Manually reducing stock.', 'jigoshop')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->reduce_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity)); if ($new_quantity < 0) { if ($old_stock < 0) { $backorder_qty = $order_item['qty']; } else { $backorder_qty = $old_stock - $order_item['qty']; } do_action('jigoshop_product_on_backorder_notification', $post_id, $_product, $backorder_qty); } // stock status notifications if ($jigoshop_options->get('jigoshop_notify_no_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= 0 && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= $new_quantity) { do_action('jigoshop_no_stock_notification', $_product); } else { if ($jigoshop_options->get('jigoshop_notify_low_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_low_stock_amount') >= $new_quantity) { do_action('jigoshop_low_stock_notification', $_product); } } } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock reduction complete.', 'jigoshop')); } else { if (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) { $order->add_order_note(__('Manually restoring stock.', 'jigoshop')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->increase_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity)); } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock restore complete.', 'jigoshop')); } else { if (isset($_POST['invoice']) && $_POST['invoice']) { // Mail link to customer jigoshop_send_customer_invoice($order->id); } } } // Error Handling if (count($jigoshop_errors) > 0) { $jigoshop_options->set('jigoshop_errors', $jigoshop_errors); } }
/** * Generate the futurepay payment iframe */ protected function call_futurepay($order_id) { // Get the order $order = new jigoshop_order($order_id); $data = array('gmid' => $this->gmid, 'reference' => $order_id . '-' . uniqid(), 'email' => $order->billing_email, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_line_1' => $order->billing_address_1, 'address_line_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $order->billing_country, 'zip' => $order->billing_postcode, 'phone' => $order->billing_phone, 'shipping_address_line_1' => $order->shipping_address_1, 'shipping_address_line_2' => $order->shipping_address_2, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'shipping_zip' => $order->shipping_postcode, 'shipping_date' => date('Y/m/d g:i:s')); // for Jigoshop 1.7, FuturePay doesn't allow negative prices (or 0.00 ) which affects discounts // with FuturePay doing the calcs, so we will bundle all products into ONE line item with // a quantity of ONE and send it that way using the final order total after shipping // and discounts are applied // all product titles will be comma delimited with their quantities $item_names = array(); if (sizeof($order->items) > 0) { foreach ($order->items as $item) { $_product = $order->get_product_from_item($item); $title = $_product->get_title(); // if variation, insert variation details into product title if ($_product instanceof jigoshop_product_variation) { $title .= ' (' . jigoshop_get_formatted_variation($_product, $item['variation'], true) . ')'; } $item_names[] = $item['qty'] . ' x ' . $title; } } // now add the one line item to the necessary product field arrays $data['sku'][] = "Products"; $data['price'][] = $order->order_total; // futurepay only needs final order amount $data['tax_amount'][] = 0; $data['description'][] = sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()) . ' = ' . implode(', ', $item_names); $data['quantity'][] = 1; try { $response = wp_remote_post(self::$request_url . 'merchant-request-order-token', array('body' => http_build_query($data), 'sslverify' => false)); // Convert error to exception if (is_wp_error($response)) { if (class_exists('WP_Exception') && $response instanceof WP_Exception) { throw $response; } else { jigoshop_log($response->get_error_message()); throw new Exception($response->get_error_message()); } } // Fetch the body from the result, any errors should be caught before proceeding $response = trim(wp_remote_retrieve_body($response)); // we need something to validate the response. Valid transactions begin with 'FPTK' if (!strstr($response, 'FPTK')) { $error_message = isset(self::$futurepay_errorcodes[$response]) ? self::$futurepay_errorcodes[$response] : __('An unknown error has occured with code = ', 'jigoshop') . $response; $order->add_order_note(sprintf(__('FUTUREPAY: %s', 'jigoshop'), $error_message)); jigoshop::add_error(sprintf(__('FUTUREPAY: %s. Please try again or select another gateway for your Order.', 'jigoshop'), $error_message)); wp_safe_redirect(get_permalink(jigoshop_get_page_id('checkout'))); exit; } /** * If we're good to go, haul in FuturePay's javascript and display the payment form * so that the customer can enter his ID and password */ echo '<div id="futurepay"></div>'; echo '<script src="' . self::$request_url . 'cart-integration/' . $response . '"></script>'; echo '<script type="text/javascript"> /*<![CDATA[*/ jQuery(window).load( function() { FP.CartIntegration(); // Need to replace form html jQuery("#futurepay").html(FP.CartIntegration.getFormContent()); FP.CartIntegration.displayFuturePay(); }); function FuturePayResponseHandler(response) { if (response.error) { // TODO: we need something better than this alert(response.code + " " + response.message); } else { window.location.replace("./?futurepay="+response.transaction_id); } } /*]]>*/ </script>'; echo '<input type="button" class="button alt" name="place_order" id="place_order" value="Place Order" onclick="FP.CartIntegration.placeOrder();" />'; } catch (Exception $e) { echo '<div class="jigoshop_error">' . $e->getMessage() . '</div>'; jigoshop_log('FUTUREPAY ERROR: ' . $e->getMessage()); } }