0% found this document useful (0 votes)
227 views2 pages

SK Request Maker - Dart

The document discusses a SKRequestMaker class in Flutter that handles all requests made by SKRequest subclasses in a consolidated way. It provides methods to start a product request by fetching information for given product identifiers and to refresh receipts by making a SKReceiptRefreshRequest.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
227 views2 pages

SK Request Maker - Dart

The document discusses a SKRequestMaker class in Flutter that handles all requests made by SKRequest subclasses in a consolidated way. It provides methods to start a product request by fetching information for given product identifiers and to refresh receipts by making a SKReceiptRefreshRequest.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

// Copyright 2019 The Chromium Authors. All rights reserved.

// Use of this source code is governed by a BSD-style license that can be


// found in the LICENSE file.

import 'dart:async';
import 'package:flutter/services.dart';
import 'package:in_app_purchase/src/channel.dart';
import 'sk_product_wrapper.dart';

/// A request maker that handles all the requests made by SKRequest subclasses.
///
/// There are multiple [SKRequest](https://developer.apple.com/documentation/sto
rekit/skrequest?language=objc) subclasses handling different requests in the `St
oreKit` with multiple delegate methods,
/// we consolidated all the `SKRequest` subclasses into this class to make reque
sts in a more straightforward way.
/// The request maker will create a SKRequest object, immediately starting it, a
nd completing the future successfully or throw an exception depending on what ha
ppened to the request.
class SKRequestMaker {
/// Fetches product information for a list of given product identifiers.
///
/// The `productIdentifiers` should contain legitimate product identifiers tha
t you declared for the products in the iTunes Connect. Invalid identifiers
/// will be stored and returned in [SkProductResponseWrapper.invalidProductIde
ntifiers]. Duplicate values in `productIdentifiers` will be omitted.
/// If `productIdentifiers` is null, an `storekit_invalid_argument` error will
be returned. If `productIdentifiers` is empty, a [SkProductResponseWrapper]
/// will still be returned with [SkProductResponseWrapper.products] being null
.
///
/// [SkProductResponseWrapper] is returned if there is no error during the req
uest.
/// A [PlatformException] is thrown if the platform code making the request fa
ils.
Future<SkProductResponseWrapper> startProductRequest(
List<String> productIdentifiers) async {
final Map<String, dynamic> productResponseMap =
await channel.invokeMapMethod<String, dynamic>(
'-[InAppPurchasePlugin startProductRequest:result:]',
productIdentifiers,
);
if (productResponseMap == null) {
throw PlatformException(
code: 'storekit_no_response',
message: 'StoreKit: Failed to get response from platform.',
);
}
return SkProductResponseWrapper.fromJson(productResponseMap);
}

/// Uses [SKReceiptRefreshRequest](https://developer.apple.com/documentation/s


torekit/skreceiptrefreshrequest?language=objc) to request a new receipt.
///
/// If the receipt is invalid or missing, you can use this API to request a ne
w receipt.
/// The [receiptProperties] is optional and it exists only for [sandbox testin
g](https://developer.apple.com/apple-pay/sandbox-testing/). In the production ap
p, call this API without pass in the [receiptProperties] parameter.
/// To test in the sandbox, you can request a receipt with any combination of
properties to test the state transitions related to [`Volume Purchase Plan`](htt
ps://www.apple.com/business/site/docs/VPP_Business_Guide.pdf) receipts.
/// The valid keys in the receiptProperties are below (All of them are of type
bool):
/// * isExpired: whether the receipt is expired.
/// * isRevoked: whether the receipt has been revoked.
/// * isVolumePurchase: whether the receipt is a Volume Purchase Plan receipt.
Future<void> startRefreshReceiptRequest({Map receiptProperties}) {
return channel.invokeMethod<void>(
'-[InAppPurchasePlugin refreshReceipt:result:]',
receiptProperties,
);
}
}

You might also like