Xamarin.InAppPurchase

What property of InAppProduct.Receipt is the "receipt" I need to pass to verifyReceipt? I've tried sending base64 encoding versions of InAppProduct.Receipt.ToString() and of the ReceiptIdentifier but Apple always sends back a 21002 - receipt-data property malformed or missing.

thanks!

Posts

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    Hi @MichaelOConnor‌,

    The InAppProductReceipt attached to a InAppProduct is not an SKPaymentTransaction which is what the Apple servers are looking for. The InAppPurchaseReceipt is an internal structure used to track elements of a purchase and is specific to the Xamarin.InAppPurchase component only.

    Per the getting started documentation, "However whenever products are purchased your application can monitor the InAppProductPurchased event of the InAppPurhcaseManager and pass the provided transaction on for validation."

    So you need to monitor the InAppProductPurchased event of the InAppPurhcaseManager which has the SKPaymentTransaction as a parameter. This is what you need to encode and pass along to Apple.

    If validation fails, call the Invalidate method of the InAppProductReceipt attached to the given InAppProduct to invalidate the purchase of the product.

    I hope that clears things up.

    Thanks,

    Kevin

  • MichaelOConnorMichaelOConnor USUniversity ✭✭

    I really appreciate your help, thank you Kevin. I am in fact using the InAppProductPurchased event and I've tried using several of the properties from the SKPaymentTransaction but I don't believe ever the whole thing. I'll try that now.

    thanks again!

  • MichaelOConnorMichaelOConnor USUniversity ✭✭

    Kevin, I finally got it to work with Apple by using this:

    transaction.TransactionReceipt.GetBase64EncodedString(NSDataBase64EncodingOptions.None);

    My concern is that TransactionReceipt is marked as deprecated. I can't use ToString() or a GetBase64... method off of the transaction object, what am I missing?

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    Hi @MichaelOConnor‌,

    I had to do a bit of research but it looks like Apple has totally changed how you access the receipt information for both Mac OS X and iOS devices. You end up using a NSUrl that is pulled from the app's main NSBundle.

    I would suggest watching Apple's Verifying Receipts video for more information. While the video is specifically using Objective-C, you should be able to pull the information that you need to code this in C#.

    Please let me know if you need anything else.

    Thanks,

    Kevin

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    All,

    I just wanted to drop a quick note saying that we have just released version 02.03 of the Xamarin.InAppPurchase component. This version specifically addresses issues that could arise when using the component with non-US English date formats and with modifications that Apple had made in the Transaction Receipt dates that were being returned.

    If there are any questions, please let me know.

    Thanks,

    Kevin

  • NBCruzNBCruz USMember ✭✭

    I'm testing this component and using code provided in the documentation. The code to add a delegate to the InAppProductPurchased is getting flagged wth an error during compile:

    PurchaseManager.InAppProductPurchased += (StoreKit.SKPaymentTransaction transaction, InAppProduct product) => {
        doSomething(product);
    };
    

    Error CS1678: Parameter 1' is declared as type StoreKit.SKPaymentTransaction' but should be `MonoTouch.StoreKit.SKPaymentTransaction' (CS1678)

    I referenced both StoreKit and InAppPurchase libraries up top, but not Monotouch which I can't find in the components list:
    using StoreKit;
    using Xamarin.InAppPurchase;
    using Xamarin.InAppPurchase.Utilities;

    And in the project I reference the Xamarin.iOS library/component, not Monotouch.

    Does the InAppPurchase component work in a project using Xamarin.iOS instead of Monotouch?

  • NBCruzNBCruz USMember ✭✭

    I figured it out - you have to use the '-Unified' version of the component.

Sign In or Register to comment.