项目作者: shoshins

项目描述 :
Apple InAppPurchase Receipt - Models, Parser, Validator
高级语言: C#
项目地址: git://github.com/shoshins/apple-receipt.git
创建时间: 2018-06-21T09:20:48Z
项目社区:https://github.com/shoshins/apple-receipt

开源协议:MIT License

下载


Project status

Statistics
GitHub release
NuGet
NuGet
NuGet
Build Status
Deploy Status
Code Quality
Last Commit

Nuget Packages Information

Apple Receipt Models

Description

Describes strongly-type representation of Apple Receipt Object.
Apple Documentation

Nuget information

Link to package

Version Downloads
Nuget NuGet

Installation:

  • (Package manager): Install-Package Apple.Receipt.Models
  • (.Net CI): dotnet add package Apple.Receipt.Models
  • (Packet CLI): paket add Apple.Receipt.Models

Apple Receipt Parser

Description

Parser for Apple Receipt that represented in base64 and encoded with ASN.1
Anatomy of a Receipt payload encoded with ASN.1

Nuget information

Link to package

Version Downloads
NuGet NuGet

Installation:

  • (Package manager): Install-Package Apple.Receipt.Parser
  • (.Net CI): dotnet add package Apple.Receipt.Parser
  • (Packet CLI): paket add Apple.Receipt.Parser

How to use:

  1. // Register DI services...
  2. services.RegisterAppleReceiptParser();
  3. ...
  4. // ... and resolve the service later.
  5. IAppleReceiptParserService parserService;
  6. ...
  7. // Get your base64 Apple Receipt
  8. const string appleAppReceipt = "{receipt_base64_string}";
  9. // Convert to Bytes
  10. byte[] data = Convert.FromBase64String(appleAppReceipt);
  11. // Get parsed receipt
  12. AppleAppReceipt receipt = parserService.GetAppleReceiptFromBytes(data);

Apple Receipt Verificator

Description

Apple Receipt Validator using Apple App Store.
Two step verification: pre-validation that can be customized and App Store verification.
Apple Receipt Validation with App Store documentation

Nuget information

Link to package

Version Downloads
NuGet NuGet

Installation:

  • (Package manager): Install-Package Apple.Receipt.Verificator
  • (.Net CI): dotnet add package Apple.Receipt.Verificator
  • (Packet CLI): paket add Apple.Receipt.Verificator

How to use:

  1. // (Optional) You can create implementation of custom validation process:
  2. services.AddScoped<IAppleReceiptCustomVerificatorService, AppleReceiptCustomVerificatorService>();
  3. ...
  4. // Fill settings:
  5. services.RegisterAppleReceiptVerificator(x =>
  6. {
  7. x.VerifyReceiptSharedSecret = "XXXX"; // Apple Shared Secret Key
  8. x.VerificationType = AppleReceiptVerificationType.Sandbox; // Verification Type: Sandbox / Production
  9. x.AllowedBundleIds = new[] {"com.mbaasy.ios.demo"}; // Array with allowed bundle ids
  10. });
  11. ...
  12. // ... and resolve the service later.
  13. IAppleReceiptVerificatorService verificator;
  14. ...
  15. // Usage option 1. Apple recommends you use that behaviour: https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store
  16. // Like 'Check on prod and in case of 21004 check on sandbox'.
  17. // BUT I CANNOT RECOMMEND THAT WAY, because Production Server cannot switch to Sandbox based on Apple Response.
  18. // Intruder would be able to send Sandbox data to your Server and get the Success response.
  19. // I Recommend the second/third options.
  20. AppleReceiptVerificationResult result = await verificator.VerifyAppleProductionReceiptAsync(appleAppReceipt).ConfigureAwait(false);
  21. if (result.Status == IAPVerificationResponseStatus.TestReceiptOnProd)
  22. {
  23. result = await verificator.VerifyAppleSandBoxReceiptAsync(appleAppReceipt).ConfigureAwait(false);
  24. }
  25. // Usage option 2. Determine if the Server was requested from Preview environment
  26. // Or App belongs to Not published apps (based on version for example).
  27. var isPreviewEnvironmentOrAppIsBelongsToUnpublishedBasedOnSomePattern = true;
  28. result = isPreviewEnvironmentOrAppIsBelongsToUnpublishedBasedOnSomePattern
  29. ? await verificator.VerifyAppleSandBoxReceiptAsync(appleAppReceipt).ConfigureAwait(false)
  30. : await verificator.VerifyAppleProductionReceiptAsync(appleAppReceipt).ConfigureAwait(false);
  31. // Usage option 3. Btw, you still has previous option to setup usage in the configuration during a Server Init step.
  32. result = await verificator.VerifyAppleReceiptAsync(appleAppReceipt).ConfigureAwait(false);
  33. // OBSOLETE USAGE (Just for Backward Compatibity):
  34. var verificationStatus = verificationResult.Status;
  35. var verificationReceipt = verificationResult.Receipt;
  36. var verificationMessage = verificationResult.Message;
  37. // USAGE (Full Apple Response Info):
  38. var verificationStatus = verificationResult.AppleVerificationResponse.StatusCode;
  39. var verificationReceipt = verificationResult.AppleVerificationResponse.Receipt;
  40. var verificationLatestReceiptInfo = verificationResult.AppleVerificationResponse.LatestReceiptInfo;
  41. var verificationPendingRenewalInfo = verificationResult.AppleVerificationResponse.PendingRenewalInfo;
  42. var verificationMessage = verificationResult.Message;