aporat / store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store
Apache License 2.0
633 stars 153 forks source link

getPendingRenewalInfo #150

Closed alexcinergy closed 3 years ago

alexcinergy commented 3 years ago

Hello!

Kindly tell me how to get protected values like from getPendingRenewalInfo class? I want to validate extension of Apple subscriptions and I need access to auto_renew_status, expiration_intent, grace_period_expires_date values.

Another kindly share the example how to use methods of class PendingRenewalInfo? There is no examples in the README.md I saw the is an instance of new PendingRenewalInfo($data) at the parseIOS7StyleReceipt method of AbstractResponse class, but it return only protected values.

Thanks in advance!

Stafox commented 3 years ago

Hi.

Any Validator response has a method getPendingRenewalInfo()

It return a collection of PendingRenewalInfo objects.

Iterate and use any public method, for example getRenewStatus()

alexcinergy commented 3 years ago

Thanks for your reply.

getPendingRenewalInfo() returns array with protected values, not object. Could you please share a small example?

Stafox commented 3 years ago

Array can not have protected values.

It returns array of objects, check the code.


    /**
     * Get the pending renewal info.
     *
     * @return PendingRenewalInfo[]
     */
    public function getPendingRenewalInfo(): array
    {
        return $this->pending_renewal_info;
    }
alexcinergy commented 3 years ago

Fix me if I wrong please:

$payment = $validator->setSharedSecret('secret_key')->setReceiptData('receipt')->validate(); $pendingRenewalInfo = $payment->getPendingRenewalInfo(); print_r($pendingRenewalInfo); Array ( [0] => ReceiptValidator\iTunes\PendingRenewalInfo Object ( [product_id:protected] => .... [auto_renew_product_id:protected] => ... [original_transaction_id:protected] => ... [auto_renew_status:protected] => [expiration_intent:protected] => 1 [grace_period_expires_date:protected] => [is_in_billing_retry_period:protected] => 0 [raw_data:protected] => Array ( [expiration_intent] => 1 [auto_renew_product_id] => ... [is_in_billing_retry_period] => 0 [product_id] => ... [original_transaction_id] => ... [auto_renew_status] => 0 ) ) )

It's array, but inside this is the object with protected values. And I can't access to $pendingRenewalInfo[0]->product_id or any other, because it's protected value.

Also I can't understand how to request getRenewStatus(). Kindly assist.

Thanks in advance!

Stafox commented 3 years ago

You need to learn the basics of php.

$payment = $validator->setSharedSecret('secret_key')->setReceiptData('receipt')->validate();
$pendingRenewalInfo = $payment->getPendingRenewalInfo();

foreach ($pendingRenewalInfo as $item) {
    $status = $item->getAutoRenewStatus();
    var_dump($status);
}