使用php,我试图获得特定的优惠券。
require_once './lib/Stripe.php';
Stripe::setApiKey(STRIPE_SK);
$response = Stripe_Coupon::retrieve('coupon id here');
print_r($response);
的print_r($响应);给了我下面的目标。我的问题是如何从对象中检索[id]?谢谢你的帮助
Stripe_Coupon Object
(
[_apiKey:protected] => sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxx
[_values:protected] => Array
(
[id] => 10percent
[created] => 1395914393
[percent_off] => 10
[amount_off] =>
[currency] =>
[object] => coupon
[livemode] =>
[duration] => repeating
[redeem_by] =>
[max_redemptions] =>
[times_redeemed] => 2
[duration_in_months] => 12
[valid] => 1
)
)
答案 0 :(得分:2)
该对象使用PHP magic __get方法。你应该能够使用:
$id = $response->id;
如果您浏览源代码,则会看到该对象最终归结为Stripe_Object类。来源: https://github.com/stripe/stripe-php/blob/master/lib/Stripe/Object.php