jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
630 stars 151 forks source link

obfuscatedAccountId returns null after PurchaseAsync #431

Closed aarcoraci closed 2 years ago

aarcoraci commented 2 years ago

Hello, I'm having some issues with the parameter ObfuscatedAccountId: I'm making the call to make a purchase sending this (it's just a base64 of the user email using the app) but although the purchase goes correct on our server (server to server notifications) and on the purchase object returned by the function the property is null.

Here is a sample piece of code:

                var obfuscatedId = Convert.ToBase64String(Encoding.UTF8.GetBytes(SessionManager.Instance.CurrentSession.Username));
                var purchase = await billing.PurchaseAsync(SUBSCRIPTION_PROFESSIONAL_YEARLY, ItemType.Subscription, obfuscatedId, obfuscatedId);

                logService.LogEvent(String.Format("Purchase made for the obfuscated id: {0}", purchase.ObfuscatedAccountId)); //purchase.ObfuscatedAccountId is null

Maybe I'm not getting this right ? how else can I tie a transaction with a user in our system if it's not by this means ?

I want to stress the purchase works (goes through and I receive a server to server notification)

Bug Information

Version Number of Plugin: 5.1.0-beta Device Tested On: iPhone 12 Simulator Tested On: --- Version of VS: Visual Studio Community 2022 for Mac Preview | Version 17.0 Preview (17.0 build 5186) Version of Xamarin: 5.0.0.2244 Versions of other things you are using:

Steps to reproduce the Behavior

Make a purchase of a subscription and include the parameter ObfuscatedAccountId

Expected Behavior

purchase.ObfuscatedAccountId being the same as the one sent on the method call

Server to server notification payload: AppAccountToken is null

Actual Behavior

purchase    {ProductId:---| IsAcknowledged:False | AutoRenewing:False | State:Purchased | Id:----- | ObfuscatedAccountId:  | ObfuscatedProfileId:  | Signature:  | OriginalJson:  | Quantity:1} 

server to server: AppAccountToken null

Code snippet

                var obfuscatedId = Convert.ToBase64String(Encoding.UTF8.GetBytes(SessionManager.Instance.CurrentSession.Username));
                var purchase = await billing.PurchaseAsync(SUBSCRIPTION_PROFESSIONAL_YEARLY, ItemType.Subscription, obfuscatedId, obfuscatedId);

                logService.LogEvent(String.Format("Purchase made for the obfuscated id: {0}", purchase.ObfuscatedAccountId)); //purchase.ObfuscatedAccountId is null

Screenshotst

jamesmontemagno commented 2 years ago

Those parameters and properties are only for Android.

You want the PurchaseToken

and the receipt data is https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling/InAppBilling.apple.cs#L216

aarcoraci commented 2 years ago

@jamesmontemagno thank you so much for your response but I don't think we are talking about the same thing. If I'm getting this right, I should be able to set a parameter to identify the user with a purchase:

https://developer.apple.com/documentation/appstoreservernotifications/appaccounttoken

In your app, you create an appAccountToken(_:) and send it to the App Store when a customer initiates an in-app purchase. The App Store returns the same value in appAccountToken in the transaction information after the customer completes the purchase.

(this is in the context of "server to server notifications")

Having this would be extremely useful. Maybe it's there and I'm missing it.

Thanks again.

jamesmontemagno commented 2 years ago

I believe that was introduced with StoreKit2 which is a swift only api and not available yet.

aarcoraci commented 2 years ago

thanks !

softlion commented 2 years ago

Could you add that to the doc plz ? Discovering that when testing is a little surprising.

Flash3001 commented 1 year ago

I am not using the library, but this thread confused me a little bit after finding it through Google. This thread is old, and maybe Apple updated the documentation later, but on the link shared by @aarcoraci they say:

If you’re using the Original API for In-App Purchase and provide a UUID in the applicationUsername property, then the appAccountToken field contains that value.

After testing it it works. If you set the UUID to ApplicationUsername the using version we have access using Xamarin it will work. https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling/InAppBilling.apple.cs#L344

jamesmontemagno commented 1 year ago

update docs