我正在尝试使用braintree支付网关创建电子商务网站。
我已使用dropin容器创建了表单,如https://www.youtube.com/watch?v=dUAk5kwKfjs
所示然后我尝试添加处理这些数据并将其发送到braintree以及将所有内容存储在我的数据库中。这是我的package com.x.scheduledReport
import com.x.Account
import com.x.XUtil
import com.x.ResponseList
import com.x.ScheduledReport
import com.x.UserService
import com.x.scheduledReports.ScheduledReportDeleteAllCommand
import com.x.scheduledReports.ScheduledReportDeleteCommand
import com.x.scheduledReports.ScheduledReportResponse
import com.x.scheduledReports.ScheduledReportUpdateCommand
import com.x.scheduledReports.ScheduledReportsCommand
import grails.transaction.Transactional
import com.x.scheduledreport.ScheduledReportUtil
@Transactional
class ScheduledReportBusinessService {
ScheduledReportService scheduledReportService
UserService userService
def list(Map params) {
if (params.start) {
params.offset = params.start
}
if (params.length) {
params.max = Math.min(params.length ? params.length as Integer : 100, 1000)
}
params.columns = XUtil.getSearchMap(params)
Account account = userService.getAccountForCurrentUser()
def scheduledReports = scheduledReportService.findAllByAccount(params, account)
params.total = scheduledReports.count
List<ScheduledReportResponse> scheduledReportResponseList = ScheduledReportUtil.toScheduledReportResponseList(scheduledReports.list)
new ResponseList(recordsTotal: scheduledReports.count, recordsFiltered: scheduledReports.count,
data: scheduledReportResponseList, draw: params.draw ? params.draw as int : 0)
}
}
处理:
PHP
这导致以下输出:
<?php include_once("connection.php"); ?>
<?php
var_dump($_POST);
session_start();
require "boot.php";
$active_country_code = $_SESSION["active_country_code"];
$active_country_braintree = $_SESSION["active_country_braintree"];
$subtotal = $_POST['subtotal'];
$vat = $_POST['vat'];
$vat_percent = $_POST['vat_percent'];
$total = $_POST['total'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$nonce = $_POST['payment_method_nonce'];
$serialized_cart_array = $_POST['cart_array'];
$cart_array = unserialize($serialized_cart_array);
$currency = $active_country_currency;
$customer_id = $_POST['customer_id'];
$address = $_POST['address'];
$params = [$customer_id,$address,$active_country_braintree,$serialized_cart_array,$subtotal,$vat,$vat_percent,$total,$currency,$active_country_code];
$sql = "INSERT INTO orders (customer_id,address_id,braintree_account,cart_array,subtotal,vat,vat_percent,total,currency,country_id,date_created,status,date_last_status_change) VALUES (?,?,?,?,?,?,?,?,?,?,now(),'created',now())";
$stmt = DB::run($sql,$params);
$order_id = DB::lastInsertId();
if (!isset($_POST['payment_method_nonce']) || $_POST['payment_method_nonce']!="") {
echo 'fail';
}
$result = Braintree_Transaction::sale([
'amount' => $total,
'orderId' => $order_id,
'merchantAccountId' => $active_country_braintree,
'paymentMethodNonce' => $nonce,
'customer' => [
'firstName' => $first_name,
'lastName' => $last_name,
'email' => $email
],
'options' => [
'submitForSettlement' => true
]
]);
if ($result->success === true) {
$transaction_id = $result->transaction->id;
$params = [$transaction_id,$order_id];
$sql = "UPDATE orders SET transaction_id=?, status='processing payment', date_last_status_change=now() WHERE id=?";
$stmt = DB::run($sql,$params);
}else{
$error = serialize($result->errors);
$params = [$error,$order_id];
$sql = "UPDATE orders SET errors=? WHERE id=?";
$stmt = DB::run($sql,$params);
}
?>
正如你所看到的,它正在呼应“失败”。因为array (size=12)
'first_name' => string 'Paddy' (length=5)
'last_name' => string 'Hallihan' (length=8)
'email' => string 'it@sublift.ie' (length=13)
'address' => string '2' (length=1)
'customer_id' => string '2' (length=1)
'subtotal' => string '196' (length=3)
'vat' => string '45.08' (length=5)
'vat_percent' => string '23' (length=2)
'total' => string '241.08' (length=6)
'guest_checkout' => string 'true' (length=4)
'cart_array' => string 'a:1:{i:0;a:4:{s:7:"item_id";s:1:"1";s:8:"quantity";d:1;s:9:"attribute";s:10:"attribute1";s:15:"attribute_price";s:3:"196";}}' (length=124)
'payment_method_nonce' => string '59698de8-8d4e-0a05-5d02-e8d512057712' (length=36)
fail
不存在,但我也可以看到它虽然是$_POST['payment_method_nonce']
,但这确实很奇怪。
实际上,它正在向我的表添加2个订单。第一个从braintree声明var_dump($_POST);
获得错误,第二个得到正确处理并从Braintree获取事务ID。
就好像页面没有运行nonce,然后刷新并正确读取发布的变量。
评论除'Cannot determine payment method'
以外的所有结果:
var_dump($_POST);
对此的任何帮助将不胜感激。
答案 0 :(得分:1)
问题是我如何提交到此页面
我正在使用:
<input type="submit" value="Pay Now">
我现在正在使用:
MongoDB
但是,我不确定为什么这首先引起了这个问题。我认为这两者都应该是一样的。