/** * Process a pre-order payment when the pre-order is released * * @param WC_Order $order * @return wp_error|void */ public function process_pre_order_release_payment($order) { $amount = $order->get_total(); $card = array('token' => get_post_meta($order->id, '_payeezy_token', true), 'expiry' => get_post_meta($order->id, '_payeezy_expiry', true), 'cardtype' => get_post_meta($order->id, '_payeezy_cardtype', true)); if (!$card) { return new WP_Error('payeezy_error', __('Customer not found', 'woocommerce-payeezy')); } $payeezy = new WC_Payeezy_API(); if ('authorize' == $this->transaction_type) { $response = $payeezy->authorize($this, $order, $amount, $card); } else { $response = $payeezy->purchase($this, $order, $amount, $card); } if (isset($response->transaction_status) && 'approved' == $response->transaction_status) { $order->payment_complete(); $amount_approved = number_format($response->amount / 100, '2', '.', ''); $message = 'authorize' == $this->transaction_type ? 'authorized' : 'completed'; $order->add_order_note(sprintf(__("Payeezy payment %s for %s. Transaction ID: %s.\n\n <strong>AVS Response:</strong> %s.\n\n <strong>CVV2 Response:</strong> %s.", 'woocommerce-payeezy'), $message, $amount_approved, $response->transaction_id, $this->get_avs_message($response->avs), $this->get_cvv_message($response->cvv2))); $tran_meta = array('transaction_id' => $response->transaction_id, 'transaction_tag' => $response->transaction_tag, 'transaction_type' => $this->transaction_type); add_post_meta($order_id, '_payeezy_transaction', $tran_meta); } else { $order->add_order_note(__('Payeezy payment declined', 'woocommerce-payeezy')); return new WP_Error('payeezy_payment_declined', __('Payment was declined - please try another card.', 'woocommerce-payeezy')); } }
/** * process_payment function. * * @access public * @param mixed $order_id * @return void */ public function process_payment($order_id) { global $woocommerce; $order = wc_get_order($order_id); $amount = $order->get_total(); $card = ''; if (isset($_POST['payeezy-token']) && !empty($_POST['payeezy-token'])) { $post_id = wc_clean($_POST['payeezy-token']); $post = get_post($post_id); $card = get_post_meta($post->ID, '_payeezy_card', true); } $payeezy = new WC_Payeezy_API(); if ('authorize' == $this->transaction_type) { $response = $payeezy->authorize($this, $order, $amount, $card); } else { $response = $payeezy->purchase($this, $order, $amount, $card); } if (isset($response->transaction_status) && 'approved' == $response->transaction_status) { $order->payment_complete(); $woocommerce->cart->empty_cart(); $amount_approved = number_format($response->amount / 100, '2', '.', ''); $message = 'authorize' == $this->transaction_type ? 'authorized' : 'completed'; $order->add_order_note(sprintf(__("Payeezy payment %s for %s. Transaction ID: %s.\n\n <strong>AVS Response:</strong> %s.\n\n <strong>CVV2 Response:</strong> %s.", 'woocommerce-payeezy'), $message, $amount_approved, $response->transaction_id, $this->get_avs_message($response->avs), $this->get_cvv_message($response->cvv2))); $tran_meta = array('transaction_id' => $response->transaction_id, 'transaction_tag' => $response->transaction_tag, 'transaction_type' => $this->transaction_type); add_post_meta($order_id, '_payeezy_transaction', $tran_meta); // Save the card if possible if (isset($_POST['payeezy-save-card']) && is_user_logged_in() && 'yes' == $this->transarmor_enabled) { $this->save_card($response); } // Return thankyou redirect return array('result' => 'success', 'redirect' => $this->get_return_url($order)); } else { if (isset($response->bank_message)) { wc_add_notice(__('Payment error: ', 'woocommerce-payeezy') . $response->bank_message, 'error'); return; } else { if ('Access denied' == $response->Error->messages[0]->description) { wc_add_notice(__('Invalid Merchant Token: Call merchant support at (866) 588-0503 to obtain a new token', 'woocommerce-payeezy'), 'error'); return; } else { wc_add_notice(__('Payment error: ', 'woocommerce-payeezy') . $response->Error->messages[0]->description, 'error'); return; } } } }