Paul Z.
Paul Z.

Reputation: 905

How to get coupon detail from Recurly_CouponRedemptionList

I'm using Recurly API 2.7, the latest version. I have trouble in fetching coupon detail from invoice object.

I want to get coupon object of first Redemption object in this result.

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

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

But $r[0] does not return Recurly_CouponRedemption object I expected.

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
        (
        )

)

Thank you for your help.

Upvotes: 1

Views: 141

Answers (1)

Rachel Davis
Rachel Davis

Reputation: 1804

Coupon details are a stub object within the redemption object.

Attached is a code snip that demonstrates calling the coupon stub and returns some sample coupon details.

The call also includes returning the coupon object in a formatted array for illustrative purposes to gain a better view of the coupon parameters/values available to be returned.

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

Upvotes: 1

Related Questions