如何从Recurly_CouponRedemptionList获取优惠券详细信息

时间:2017-01-11 16:38:16

标签: php recurly

我使用的是最新版Recurly API 2.7。我无法从发票对象中获取优惠券详细信息。

我希望在此结果中获得第一个Redemption对象的优惠券对象。

$i = $ss->invoice->get();

if ($i->redemptions) {
    $r = $i->redemptions->get();
    print_r($r);
    if ($r->count > 0) {
        $coupon = $r[0]->coupon->get();
    }
}

但$ r [0]不会返回我预期的Recurly_CouponRedemption对象。

Recurly_CouponRedemptionList Object
(
    [_position:Recurly_Pager:private] => 0
    [_count:protected] => 1
    [_objects:protected] => Array
        (
            [0] => Recurly_CouponRedemption Object
                (
                    [_values:protected] => Array
                        (
                            [coupon] => Recurly_Stub Object
                                (
                                    [objectType] => coupon
                                    [_href:protected] => https://xxx.recurly.com/v2/accounts/test
                                    [_client:protected] => Recurly_Client Object
                                        (
                                            [_apiKey:Recurly_Client:private] => 
                                            [_acceptLanguage:Recurly_Client:private] => en-US
                                        )

                                    [_links:protected] => Array
                                        (
                                        )

                                )

                            [account] => Recurly_Stub Object
                                (
                                    [objectType] => account
                                    [_href:protected] => https://xxx.recurly.com/v2/accounts/test
                                    [_client:protected] => Recurly_Client Object
                                        (
                                            [_apiKey:Recurly_Client:private] => 
                                            [_acceptLanguage:Recurly_Client:private] => en-US
                                        )

                                    [_links:protected] => Array
                                        (
                                        )

                                )

                            [uuid] => 0b00000000000000000000000
                            [single_use] => 
                            [total_discounted_in_cents] => 500
                            [currency] => USD
                            [state] => active
                            [coupon_code] => 5off
                            [created_at] => DateTime Object
                                (
                                    [date] => 2017-01-11 16:30:09
                                    [timezone_type] => 2
                                    [timezone] => Z
                                )

                            [updated_at] => DateTime Object
                                (
                                    [date] => 2017-01-11 16:30:09
                                    [timezone_type] => 2
                                    [timezone] => Z
                                )

                        )

                    [_unsavedKeys:protected] => Array
                        (
                        )

                    [_errors:protected] => Recurly_ErrorList Object
                        (
                            [transaction] => 
                            [transaction_error] => 
                            [errors:Recurly_ErrorList:private] => Array
                                (
                                )

                        )

                    [_href:protected] => 
                    [_client:protected] => Recurly_Client Object
                        (
                            [_apiKey:Recurly_Client:private] => 
                            [_acceptLanguage:Recurly_Client:private] => en-US
                        )

                    [_links:protected] => Array
                        (
                        )

                )

        )

    [_href:protected] => test
    [_client:protected] => Recurly_Client Object
        (
            [_apiKey:Recurly_Client:private] => 
            [_acceptLanguage:Recurly_Client:private] => en-US
        )

    [_links:protected] => Array
        (
        )

)

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

优惠券详细信息是兑换对象中的存根对象。

附件是一个代码片段,演示调用优惠券存根并返回一些样本优惠券详细信息。

该调用还包括将格式化数组中的优惠券对象返回以用于说明目的,以更好地查看可返回的优惠券参数/值。

https://gist.github.com/ianatrecurly/fc47fb5c98deb999cde182402049050b