簡體   English   中英

如何從這個對象中獲取價值?

[英]How to retrieve value from this object?

使用php,我嘗試獲取特定優惠券。

require_once './lib/Stripe.php';
Stripe::setApiKey(STRIPE_SK);
$response = Stripe_Coupon::retrieve('coupon id here');
print_r($response);

print_r($ response); 給了我下面的物體。 我的問題是如何從對象中檢索[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
       )
)

該對象正在使用PHP魔術__get方法。 您應該可以使用:

$id = $response->id;

如果遍歷源代碼,您會看到對象最終歸結為Stripe_Object類。 來源在這里: https : //github.com/stripe/stripe-php/blob/master/lib/Stripe/Object.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM