gpt4 book ai didi

php - 使用 PHP 存储 JSON 值

转载 作者:太空宇宙 更新时间:2023-11-03 12:00:04 25 4
gpt4 key购买 nike

我正在使用 stripe 支付系统,基本上发生的事情是在收费后,我输出 json 值,以及我想存储 id 的位置以便捕获费用。

下面是收费的方式

try {
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'cad',
'capture' => 'false',

'description'=> $courseTitle

));

echo $charge;
} catch(\Stripe\Error\Card $e) {
// The card has been declined
$stripChargeValid = false;
echo "failed";

}

下面是 echo

Stripe\Charge JSON: { "id": "ch_15usNKIOMQSe8X844GzjEpyM", "object": "charge", "created": 1429826450, "livemode": false, "paid": true, "status": "succeeded", "amount": 41000, "currency": "cad", "refunded": false, "source": { "id": "card_15usMsIOMQSe8X84foA2Qb69", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 1, "exp_year": 2016, "fingerprint": "GLlDGRtbDBjmZDdb", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": "pass", "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null, "metadata": [], "customer": "cus_676avKg8aDycIL" }, "captured": false, "balance_transaction": null, "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": "cus_676avKg8aDycIL", "invoice": null, "description": "Microsoft Office 2013: Transition from Office 2007\/2010", "dispute": null, "metadata": [], "statement_descriptor": null, "fraud_details": [], "receipt_email": "jonathanetienne@live.com", "receipt_number": null, "shipping": null, "application_fee": null, "refunds": { "object": "list", "total_count": 0, "has_more": false, "url": "\/v1\/charges\/ch_15usNKIOMQSe8X844GzjEpyM\/refunds", "data": [] } }

我想获取 id 值,以便将其发布到 mysqli 查询中

更新:

object(Stripe\Charge)#25 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#22 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) ""
}
["_values":protected]=>
array(27) {
["id"]=>
string(27) "ch_15uu0dIOMQSe8X84gJIVis9y"
["object"]=>
string(6) "charge"
["created"]=>
int(1429832731)
["livemode"]=>
bool(false)
["paid"]=>
bool(true)
["status"]=>
string(9) "succeeded"
["amount"]=>
int(338400)
["currency"]=>
string(3) "cad"
["refunded"]=>
bool(false)
["source"]=>
object(Stripe\Card)#26 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#22 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) ""
}
["_values":protected]=>
array(22) {
["id"]=>
string(29) "card_15utkNIOMQSe8X845N5xbl7y"
["object"]=>
string(4) "card"
["last4"]=>
string(4) "4242"
["brand"]=>
string(4) "Visa"
["funding"]=>
string(6) "credit"
["exp_month"]=>
int(1)
["exp_year"]=>
int(2016)
["fingerprint"]=>
string(16) "GLlDGRtbDBjmZDdb"
["country"]=>
string(2) "US"
["name"]=>
NULL
["address_line1"]=>
NULL
["address_line2"]=>
NULL
["address_city"]=>
NULL
["address_state"]=>
NULL
["address_zip"]=>
NULL
["address_country"]=>
NULL
["cvc_check"]=>
NULL
["address_line1_check"]=>
NULL
["address_zip_check"]=>
NULL
["dynamic_last4"]=>
NULL
["metadata"]=>
object(Stripe\AttachedObject)#29 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#22 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) ""
}
["_values":protected]=>
array(0) {
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#33 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#34 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}
["customer"]=>
string(18) "cus_678HJKOahVnt6v"
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#30 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#31 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}
["captured"]=>
bool(false)
["balance_transaction"]=>
NULL
["failure_message"]=>
NULL
["failure_code"]=>
NULL
["amount_refunded"]=>
int(0)
["customer"]=>
string(18) "cus_678HJKOahVnt6v"
["invoice"]=>
NULL
["description"]=>
string(39) "PMP Exam Prep Training (PMBOK Guide V5)"
["dispute"]=>
NULL
["metadata"]=>
object(Stripe\AttachedObject)#32 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#22 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) ""
}
["_values":protected]=>
array(0) {
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#36 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#37 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}
["statement_descriptor"]=>
NULL
["fraud_details"]=>
array(0) {
}
["receipt_email"]=>
string(24) ""
["receipt_number"]=>
NULL
["shipping"]=>
NULL
["application_fee"]=>
NULL
["refunds"]=>
object(Stripe\Collection)#35 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#22 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) ""
}
["_values":protected]=>
array(5) {
["object"]=>
string(4) "list"
["total_count"]=>
int(0)
["has_more"]=>
bool(false)
["url"]=>
string(47) "/v1/charges/ch_15uu0dIOMQSe8X84gJIVis9y/refunds"
["data"]=>
array(0) {
}
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#39 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#40 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#27 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#28 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}

更新:

下面是输出:

$charge_json = $charge->__toJSON(); 
echo "<pre>";
var_dump($charge_json);
echo "</pre>";

string(1677) "{
"id": "ch_15vDxQIOMQSe8X84NBckjjil",
"object": "charge",
"created": 1429909412,
"livemode": false,
"paid": true,
"status": "succeeded",
"amount": 41000,
"currency": "cad",
"refunded": false,
"source": {
"id": "card_15vDwlIOMQSe8X843FPN4gAt",
"object": "card",
"last4": "4242",
"brand": "Visa",
"funding": "credit",
"exp_month": 1,
"exp_year": 2016,
"fingerprint": "GLlDGRtbDBjmZDdb",
"country": "US",
"name": "john",
"address_line1": "",
"address_line2": null,
"address_city": "",
"address_state": "",
"address_zip": "",
"address_country": null,
"cvc_check": "pass",
"address_line1_check": "pass",
"address_zip_check": "pass",
"dynamic_last4": null,
"metadata": [],
"customer": "cus_67StWh5kSlXJWN"
},
"captured": false,
"balance_transaction": null,
"failure_message": null,
"failure_code": null,
"amount_refunded": 0,
"customer": "cus_67StWh5kSlXJWN",
"invoice": null,
"description": "",
"dispute": null,
"metadata": [],
"statement_descriptor": null,
"fraud_details": [],
"receipt_email": "",
"receipt_number": null,
"shipping": null,
"application_fee": null,
"refunds": {
"object": "list",
"total_count": 0,
"has_more": false,
"url": "\/v1\/charges\/ch_15vDxQIOMQSe8X84NBckjjil\/refunds",
"data": []
}
}"

最佳答案

您的 echo 指令正在从 Object 调用 __toString 方法.然而,您的费用变量是一个 PHPStripeObject。

话虽如此,我想您可以执行以下操作以确保在末尾获得一个包含您的数据的数组:

try {
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'cad',
'capture' => 'false',
'description'=> $courseTitle
));
$chargeArray = \Stripe\Util\Util::convertStripeObjectToArray($charge);
$id = $chargeArray['id'];
...
} catch(\Stripe\Error\Card $e) {
// The card has been declined
$stripChargeValid = false;
echo "failed";
}

关于php - 使用 PHP 存储 JSON 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29835541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com