错误: [16-May-2018 22:16:06 UTC] PHP致命错误:未捕获的异常'Stripe \ Error \ InvalidRequest',消息'无效的源对象:必须是字典或一个非空字符串。请参阅/home/autravelservice/public_html/wp-content/plugins/ats/libraries/stripe-php-6.0.0/lib/ApiRequestor.php:120中来自API请求'req_6uGybuHR3adjqW'的https://stripe.com/docs''处的API文档
请看我的代码有什么我做错了吗?
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey($sk);
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $payment_details['token'];
//echo 'pay:' . $pay_amount;
// Create customer:
$i = 0;
foreach(get_field('applicant', $post_id) as $applicant) {
if($i++ == 0) {
$applicant_details = $applicant['applicant_details'];
$contact_details = $applicant['contact_details'];
$name_first = $applicant_details['first_name'];
$name_last = $applicant_details['last_name'];
$email = $contact_details['email'];
$user_info = array("First Name" => $name_first, "Last Name" => $name_last);
$customer = \Stripe\Customer::create(array(
"email" => $email,
"card" => $token,
"metadata" => $user_info
));
// Charge the user's card:
$charge = \Stripe\Charge::create(array(
"customer" => $customer->id,
"amount" => $pay_amount,
"currency" => "usd",
"description" => "Australian Travel Service"
));
}
}
if($charge->status == 'succeeded') {
$counter = range(1, 5);
$counter= shuffle($counter);
$orderid = 'AUS-CU-' . date('Ymd') . $post_id . $counter;
echo '<input type="hidden" name="orderid" id="app_order_id" value="'.$orderid.'">';
echo '<input type="hidden" id="applicant_count" value="'.$applicant_count.'">';
echo '<input type="hidden" id="processing_type" value="'.$processing_fee_type[0].'">';
echo '<input type="hidden" id="order_total" value="'.$pay_amount.'">';
appFormAdminMail($post_id, $orderid);
acf_form(array(
'id' => 'survey-form',
'post_id' => $post_id,
'field_groups' => array(158),
'return' => './survey-thank-you/?record=%post_id%',
'submit_value' => 'SUBMIT SURVEY',
'html_submit_button' => '<button type="submit" class="acf-btn red-btn rounded-btn">%s</button>'
));
} else {
echo 'Payment error...';
}
答案 0 :(得分:0)
问题似乎与您的$token
变量有关,可能是格式错误或遗失。我建议你echo
查看价值是什么,或者分享更多关于如何创建$payment_details
的代码。