我在一段代码中挣扎了一个多星期。 我在我的Codeigniter应用程序中使用PHP SDK实现了Braintree,我遇到了这个问题:
一切都在沙箱模式下按预期工作,但当我进入生产模式时,重定向失败,页面被重定向回订单确认,即使CC收费并且两封电子邮件都已发送。
这是我的控制器:
function order_confirmation()
{
require_once('application/libraries/braintree/lib/Braintree.php');
Braintree_Configuration::environment('production');
Braintree_Configuration::merchantId('MY_MERCHANT_ID');
Braintree_Configuration::publicKey('MY_PUBLIC_KEY');
Braintree_Configuration::privateKey('MY_PRIVATE_KEY');
if ($this->input->post('checkout'))
{
$price = 24.99;
$quantity = 1;
if ($this->input->post('shipping') == 1)
$shipping_price = 0;
elseif ($this->input->post('shipping') == 2)
$shipping_price = 6.99;
$amount = $price * $quantity + $shipping_price;
//BrainTree payment process
$result = Braintree_Transaction::sale(array(
'amount' => $amount,
'creditCard' => array(
'number' => $this->input->post('credit_card_number'),
'expirationDate' => $this->input->post('expiration_month') . '/' . $this->input->post('expiration_year'),
'cvv' => $this->input->post('cvv')
),
'options' => [
'submitForSettlement' => True
]
));
if ($result->success)
{
// I left only the first and last name field to save up space
$first_name = $this->db->escape($this->session->userdata('first_name'));
$last_name = $this->db->escape($this->session->userdata('last_name'));
$date_created = $this->db->escape(time());
// Add the order
$this->shop_model->add_order($first_name, $last_name, $transaction_id, $date_created);
$order_id = $this->db->insert_id();
$product_id = $this->db->escape($this->input->post('product_id'));
// Add the order items
$this->shop_model->add_order_items($order_id, $product_id, $quantity, $price);
$data['site_name'] = $this->config->item('website_name');
$data['order'] = $this->shop_model->get_order($order_id);
$data['order_items'] = $this->shop_model->get_order_items($order_id);
$customer_email = $this->session->userdata('email');
// Send the email notification to the merchant
send_html_email('order_confirmation_merchant', $this->config->item('primary_email'), $this->config->item('website_name'), $this->config->item('primary_email'), 'shop', $data);
// Send the order confirmation to the customer
send_html_email('order_confirmation_customer', $this->config->item('primary_email'), $this->config->item('website_name'), $customer_email, 'shop', $data);
redirect(SHOP . '/checkout-success');
// header("Location: checkout-success");
// echo '<script language="JavaScript">document.location.href="' . base_url() . SHOP . '/checkout-success' . '"</script>' . "\n";
}
else
{
redirect(SHOP . '/checkout-error');
}
}
$this->template->set_template('no_sidebar');
$this->template->write('meta_description', 'Order confirmation');
$this->template->write('meta_keywords', 'Order confirmation');
$this->template->write('title', 'Order confirmation');
$this->template->write_view('header', 'frontend/header');
$this->template->write_view('section', 'frontend/shop/order_confirmation'/*, $data*/);
$this->template->write_view('footer', 'frontend/footer');
$this->template->render();
}
正如您所看到的,我尝试了多种重定向方法(Codeigniter重定向(),本机PHP,Javascript)但没有成功。如前所述,我确实看到沙盒模式下的成功页面和错误页面,如果我输入伪造的CC,但没有成功页面,只有我的订单确认表格,在生产模式下,即使CC收费,订单添加在数据库和发送的电子邮件。
我想提一下,该网站有SSL证书,我使用Mozilla Firefox,Google Chrome,Microsoft Edge进行了测试。没有JS错误,没有PHP警告。
任何答案都将不胜感激。 谢谢!