/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @uses Simplify_BadRequestException * @return bool|WP_Error */ public function process_subscription_payment($order, $amount = 0) { if (0 == $amount) { // Payment complete $order->payment_complete(); return true; } if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order_item['name']) . ' ' . sprintf(__('(Order #%s)', 'woocommerce'), $order->get_order_number()); $customer_id = get_post_meta($order->id, '_simplify_customer_id', true); if (!$customer_id) { return new WP_Error('simplify_error', __('Customer not found', 'woocommerce')); } try { // Charge the customer $payment = Simplify_Payment::createPayment(array('amount' => $amount * 100, 'customer' => $customer_id, 'description' => trim(substr($subscription_name, 0, 1024)), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id, 'card.addressCity' => $order->billing_city, 'card.addressCountry' => $order->billing_country, 'card.addressLine1' => $order->billing_address_1, 'card.addressLine2' => $order->billing_address_2, 'card.addressState' => $order->billing_state, 'card.addressZip' => $order->billing_postcode)); } catch (Exception $e) { $error_message = $e->getMessage(); if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { $error_message = ''; foreach ($e->getFieldErrors() as $error) { $error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')'; } } $order->add_order_note(sprintf(__('Simplify payment error: %s', 'woocommerce'), $error_message)); return new WP_Error('simplify_payment_declined', $e->getMessage(), array('status' => $e->getCode())); } if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %s, Auth Code: %s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
function woocommerce_atos_automatic_response($atts) { $atos = new woocommerce_atos(); if (isset($_POST['DATA'])) { $transauthorised = false; $data = escapeshellcmd(sanitize_text_field($_POST['DATA'])); $message = sprintf('message=%s', $data); $pathfile = sprintf('pathfile=%s', $atos->pathfile); $path_bin_response = $atos->path_bin_response; $result = exec("{$path_bin_response} {$pathfile} {$message}"); $results = explode('!', $result); $response = array('code' => $results[1], 'error' => $results[2], 'merchantid' => $results[3], 'merchantcountry' => $results[4], 'amount' => $results[5], 'transactionid' => $results[6], 'paymentmeans' => $results[7], 'transmissiondate' => $results[8], 'paymenttime' => $results[9], 'paymentdate' => $results[10], 'responsecode' => $results[11], 'paymentcertificate' => $results[12], 'authorisationid' => $results[13], 'currencycode' => $results[14], 'cardnumber' => $results[15], 'cvvflag' => $results[16], 'cvvresponsecode' => $results[17], 'bankresponsecode' => $results[18], 'complementarycode' => $results[19], 'complementaryinfo' => $results[20], 'returncontext' => $results[21], 'caddie' => $results[22], 'receiptcomplement' => $results[23], 'merchantlanguage' => $results[24], 'language' => $results[25], 'customerid' => $results[26], 'orderid' => $results[27], 'customeremail' => $results[28], 'customeripaddress' => $results[29], 'captureday' => $results[30], 'capturemode' => $results[31], 'data' => $results[32]); $order = new WC_order($response['orderid']); if ($response['responsecode'] == '' && $response['error'] == '') { $atos->msg['class'] = 'error'; $atos->msg['message'] = __('Thank you for shopping with us. However, the transaction has been declined.', 'woocommerce-atos'); } elseif ($response['responsecode'] != 0) { $atos->msg['class'] = 'error'; $atos->msg['message'] = __('Thank you for shopping with us. However, the transaction has been declined.', 'woocommerce-atos'); } else { if ($response['responsecode'] == 00) { $transauthorised = true; $order->update_status('processing'); $order->payment_complete($response['transactionid']); $order->add_order_note(__('Payment accepted by the bank', 'woocommerce-atos')); WC()->cart->empty_cart(); } } if ($transauthorised == false) { $order->update_status('failed'); $order->add_order_note('Failed'); $order->add_order_note($atos->msg['message']); } } else { // end of check post echo __('Precondition failed.', 'woocommerce-atos'); } }
/** * do payment function. * * @param WC_order $order * @param int $amount (default: 0) * @uses Simplify_BadRequestException * @return bool|WP_Error */ public function do_payment($order, $amount = 0, $token = array()) { if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } try { // Charge the customer $data = array('amount' => $amount * 100, 'description' => sprintf(__('%1$s - Order #%2$s', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order->get_order_number()), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->get_id()); $data = array_merge($data, $token); $payment = Simplify_Payment::createPayment($data); } catch (Exception $e) { $error_message = $e->getMessage(); if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { $error_message = ''; foreach ($e->getFieldErrors() as $error) { $error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')'; } } $order->add_order_note(sprintf(__('Simplify payment error: %s', 'woocommerce'), $error_message)); return new WP_Error('simplify_payment_declined', $e->getMessage(), array('status' => $e->getCode())); } if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %1$s, Auth Code: %2$s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @return bool|WP_Error */ public function process_subscription_payment($order = '', $amount = 0) { $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce'), esc_html(get_bloginfo('name')), $order_item['name']) . ' ' . sprintf(__('(Order %s)', 'woocommerce'), $order->get_order_number()); if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } $customer_id = get_post_meta($order->id, '_simplify_customer_id', true); if (!$customer_id) { return new WP_Error('simplify_error', __('Customer not found', 'woocommerce')); } // Charge the customer $payment = Simplify_Payment::createPayment(array('amount' => $amount * 100, 'customer' => $customer_id, 'description' => trim(substr($subscription_name, 0, 1024)), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id, 'card.addressCity' => $order->billing_city, 'card.addressCountry' => $order->billing_country, 'card.addressLine1' => $order->billing_address_1, 'card.addressLine2' => $order->billing_address_2, 'card.addressState' => $order->billing_state, 'card.addressZip' => $order->billing_postcode)); if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %s, Auth Code: %s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
function child_transaction($type, $uid, $order_id, $amount, $reason = '') { global $woocommerce; $order = new WC_order($order_id); //get the uid from order and compare to md5 in the $_GET $post_uid = get_post_meta($order_id, '_uid', true); $check_uid = md5($post_uid); if ($check_uid != $uid) { exit(__('UID is not correct', 'woocommerce-begateway')); } $messages = array('void' => array('not_possible' => __('Wrong order status. Void is not possible.', 'woocommerce-begateway'), 'status' => __('Void status', 'woocommerce-begateway'), 'failed' => __('Void attempt failed', 'woocommerce-begateway'), 'success' => __('Payment voided', 'woocommerce-begateway')), 'capture' => array('not_possible' => __('Wrong order status. Capture is not possible.', 'woocommerce-begateway'), 'status' => __('Capture status', 'woocommerce-begateway'), 'failed' => __('Capture attempt failed', 'woocommerce-begateway'), 'success' => __('Payment captured', 'woocommerce-begateway')), 'refund' => array('not_possible' => __('Wrong order status. Refund is not possible.', 'woocommerce-begateway'), 'status' => __('Refund status', 'woocommerce-begateway'), 'failed' => __('Refund attempt failed', 'woocommerce-begateway'), 'success' => __('Payment refunded', 'woocommerce-begateway'))); //check order status is on hold exit if not if (in_array($type, array('capture', 'void')) && $order->status != 'on-hold') { exit($messages[$type]['not_possible']); } if (in_array($type, array('refund')) && $order->status != 'processing') { exit($messages[$type]['not_possible']); } // now send data to the server $klass = '\\beGateway\\' . ucfirst($type); $transaction = new $klass(); $transaction->setParentUid($post_uid); $transaction->money->setCurrency(get_woocommerce_currency()); $transaction->money->setAmount($amount); if ($type == 'refund') { if (isset($reason) && !empty($reason)) { $transaction->setReason($reason); } else { $transaction->setReason(__('Refunded from Woocommerce', 'woocommerce-begateway')); } } $response = $transaction->submit(); //determine status if success if ($response->isSuccess()) { if ($type == 'capture') { $order->payment_complete(); $order->add_order_note($messages[$type]['success'] . '. UID: ' . $response->getUid()); update_post_meta($order_id, '_uid', $response->getUid()); } elseif ($type == 'void') { $order->update_status('cancelled', $messages[$type]['success'] . '. UID: ' . $response->getUid()); } elseif ($type == 'refund') { $order->update_status('refunded', $messages[$type]['success'] . '. UID: ' . $response->getUid()); } if ('yes' == $this->debug) { $this->log->add('begateway', $messages[$type]['status'] . ': ' . $response->getMessage()); } update_post_meta($order_id, '_bt_admin_message', $messages[$type]['success']); } else { if ('yes' == $this->debug) { $this->log->add('begateway', $messages[$type]['failed'] . ': ' . $response->getMessage()); } update_post_meta($order_id, '_bt_admin_error', $messages[$type]['failed'] . ': ' . $response->getMessage()); } $location = get_post_meta($order_id, '_return_url', true); delete_post_meta($order_id, '_return_url', true); header('Location:' . $location); exit; }
/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @return bool|WP_Error */ public function process_subscription_payment($order = '', $amount = 0) { $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce-payment-gateway-boilerplate'), esc_html(get_bloginfo('name')), $order_item['name']) . ' ' . sprintf(__('(Order %s)', 'woocommerce-payment-gateway-boilerplate'), $order->get_order_number()); if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-payment-gateway-boilerplate')); } if ('APPROVED' == $payment['status']) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Gateway name payment approved (ID: %s)', 'woocommerce-payment-gateway-boilerplate'), $payment['id'])); return true; } else { $order->add_order_note(__('Gateway name payment declined', 'woocommerce-payment-gateway-boilerplate')); return new WP_Error('gateway_name_payment_declined', __('Payment was declined - please try again.', 'woocommerce-payment-gateway-boilerplate')); } }