iaphub / react-native-iaphub

The easiest way to implement IAP (In-app purchase) in your React Native app.
https://www.iaphub.com/
MIT License
319 stars 21 forks source link

Refund webhook not being called (at least on dev env, auto subscription and on Google) #57

Closed SrBrahma closed 3 years ago

SrBrahma commented 3 years ago

Hey, my purchase system is almost working 100%, purchase, paused, renew etc webhooks being called as they should, but today when testing the Refund (so I can disable the features to the user) in dev env, no webhook was being called when the refund was processed.

I received the successful refund e-mail from Google, with a matching orderId (GPA.3362-0910-4103-82193), but still nothing happened by IAPHUB. The only webhook received after the refund, was the purchase expiration itself (which maybe shouldn't be called, as the refund happens before the expire)

Purchase webhook, before refund ```js { id: '6006cef1a897c30e257b8617', type: 'purchase', createdDate: '2021-01-19T12:22:09.402Z', version: '1.2.0', data: { id: '6006cef1a897c30e257b8613', purchaseDate: '2021-01-19T12:22:04.536Z', quantity: 1, platform: 'android', country: 'BR', tags: {}, orderId: 'GPA.3362-0910-4103-82193', app: '5fcee799c9cf7c0eb55c04dd', user: '6005fd6a14a85c0ea55f279a', product: '5fd7b8f48195d60eaa122705', receipt: '6006cef0a897c30e257b8610', listing: '5fd18d765c877f0e20fe992c', store: '5fd18d765c877f0e20fe992e', currency: 'BRL', price: 74.99, convertedCurrency: 'BRL', convertedPrice: 74.99, isSandbox: true, isRefunded: false, isSubscription: true, isSubscriptionActive: true, isSubscriptionRenewable: true, isSubscriptionRetryPeriod: false, isSubscriptionGracePeriod: false, isSubscriptionPaused: false, isTrialConversion: false, subscriptionState: 'active', subscriptionPeriodType: 'normal', expirationDate: '2021-01-19T12:33:59.596Z', originalPurchase: '6006cef1a897c30e257b8613', userId: 'EW4UWtLtJihjoS1yeSszTmC8jlgx', productSku: 'app_contador.os_android.id_license.id2_1.t_3m.v_2', productType: 'renewable_subscription' } } ```
Expire webhook, some time after the refund (but not actually the refund webhook) ```js { id: '6006d218452f872787e95519', type: 'subscription_expire', createdDate: '2021-01-19T12:35:36.819Z', version: '1.2.0', data: { id: '6006cef1a897c30e257b8613', purchaseDate: '2021-01-19T12:22:04.536Z', quantity: 1, platform: 'android', country: 'BR', tags: {}, orderId: 'GPA.3362-0910-4103-82193', app: '5fcee799c9cf7c0eb55c04dd', user: '6005fd6a14a85c0ea55f279a', product: '5fd7b8f48195d60eaa122705', receipt: '6006cef0a897c30e257b8610', listing: '5fd18d765c877f0e20fe992c', store: '5fd18d765c877f0e20fe992e', currency: 'BRL', price: 74.99, convertedCurrency: 'BRL', convertedPrice: 74.99, isSandbox: true, isRefunded: false, isSubscription: true, isSubscriptionActive: false, isSubscriptionRenewable: false, isSubscriptionRetryPeriod: false, isSubscriptionGracePeriod: false, isSubscriptionPaused: false, isTrialConversion: false, subscriptionState: 'expired', subscriptionPeriodType: 'normal', subscriptionCancelReason: 'customer_cancelled', expirationDate: '2021-01-19T12:23:37.797Z', originalPurchase: '6006cef1a897c30e257b8613', userId: 'EW4UWtLtJihjoS1yeSszTmC8jlgx', productSku: 'app_contador.os_android.id_license.id2_1.t_3m.v_2', productType: 'renewable_subscription' } } ```

Questions:

1) Is this intended / known bug? 2) Will that also happen on prod? 3) On a working-as-expected refund webhook, what will be the subscriptionState field?

iaphub commented 3 years ago

Hi @SrBrahma,

This is not a bug, unfortunately Google isn't returning from the receipt when a subscription is refunded (we need to add more infos about it in the doc).

Otherwise when a subscription is refunded you'll only receive a subscription_expire webhook and the subscriptionState property will be expired but you can check the isRefunded property to detect if the transaction has been detected as refunded.

SrBrahma commented 3 years ago

But the expire webhook will only happen at the end of the original purchase? If so, could be exploited by users who know about that. Feel free to delete this issue if so

iaphub commented 3 years ago

No, after the subscription is refunded Google update the expiration date, the subscription will expire right after it is refunded. We will try to enhance the reporting of a refunded subscription on Android in the coming weeks.

SrBrahma commented 3 years ago

I see. It is good enough for my needs! Thanks!

On qua, 20 de jan de 2021 23:07 iaphub notifications@github.com wrote:

No, after the subscription is refunded Google update the expiration date, the subscription will expire right after it is refunded. We will try to enhance the reporting of a refunded subscription on Android in the coming weeks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/iaphub/react-native-iaphub/issues/57#issuecomment-764183000, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGW7JDXMWPNJ3S5GASE2NSTS26D6ZANCNFSM4WIXGZTQ .