-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* set min ios version to 15 * consolidated buy methods * removed checks for older versions of ios * cleared most errors * swiftlint * continue migration, purchases * return promises to class * moved utils to ios * clean up promises and error codes * serialized Transactions * removed remaining old methods, added serialization * default to Xcode 4 spaces * Split files * Added more transaction methods * removed global autofinish * fix lint on doc Co-authored-by: Andres Aguilar <andres.aguilar@nfl.com>
- Loading branch information
1 parent
f26544a
commit ba9482f
Showing
13 changed files
with
663 additions
and
1,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Publish main package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
cache: 'yarn' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Remove example code | ||
run: rm -rf IapExample | ||
|
||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: Run lint scripts | ||
run: yarn lint:ci | ||
|
||
- name: Verify no files have changed after auto-fix | ||
run: git diff -- ":(exclude)IapExample/*" --exit-code HEAD | ||
|
||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// IapSerializationUtils.swift | ||
// RNIap | ||
// | ||
// Created by Aguilar Andres on 8/18/22. | ||
// | ||
|
||
import Foundation | ||
import StoreKit | ||
|
||
func serialize(_ p: Product) -> [String: Any?] { | ||
return ["displayName": p.displayName, | ||
"description": p.description, | ||
"id": p.id, | ||
"displayPrice": p.displayPrice, | ||
"price": p.price, | ||
"isFamilyShareable": p.isFamilyShareable, | ||
"subscription": p.subscription?.subscriptionGroupID, | ||
"jsonRepresentation": p.jsonRepresentation, | ||
"debugDescription": p.debugDescription, | ||
"subscription": serialize(p.subscription), | ||
"type": serialize(p.type) | ||
] | ||
} | ||
|
||
func serialize(_ e: Error?) -> [String: Any?]? { | ||
guard let e = e else {return nil} | ||
return ["localizedDescription": e.localizedDescription] | ||
} | ||
|
||
func serialize(_ si: Product.SubscriptionInfo?) -> [String: Any?]? { | ||
guard let si = si else {return nil} | ||
return [ | ||
"subscriptionGroupID": si.subscriptionGroupID, | ||
"promotionalOffers": si.promotionalOffers.map {(offer: Product.SubscriptionOffer) in serialize(offer)}, | ||
"introductoryOffer": serialize(si.introductoryOffer), | ||
"subscriptionPeriod": si.subscriptionPeriod | ||
] | ||
} | ||
|
||
func serialize(_ so: Product.SubscriptionOffer?) -> [String: Any?]? { | ||
guard let so = so else {return nil} | ||
return [ | ||
"id": so.id, | ||
"price": so.price, | ||
"displayPrice": so.displayPrice, | ||
"type": so.type, | ||
"paymentMode": so.paymentMode, | ||
"period": so.period, | ||
"periodCount": so.periodCount | ||
] | ||
} | ||
|
||
// Transaction | ||
func serialize(_ t: Transaction) -> [String: Any?] { | ||
return ["id": t.id, | ||
"appBundleID": t.appBundleID, | ||
"offerID": t.offerID, | ||
"subscriptionGroupID": t.subscriptionGroupID, | ||
"appAccountToken": t.appAccountToken, | ||
"debugDescription": t.debugDescription, | ||
"deviceVerification": t.deviceVerification, | ||
"deviceVerificationNonce": t.deviceVerificationNonce, | ||
"expirationDate": t.expirationDate, | ||
"isUpgraded": t.isUpgraded, | ||
"jsonRepresentation": t.jsonRepresentation, | ||
"offerType": serialize(t.offerType), | ||
"expirationDate": t.expirationDate, | ||
"originalID": t.originalID, | ||
"originalPurchaseDate": t.originalPurchaseDate, | ||
"ownershipType": serialize(t.ownershipType), | ||
"productType": serialize(t.productType), | ||
"productID": t.productID, | ||
"purchasedQuantity": t.purchasedQuantity, | ||
"revocationDate": t.revocationDate, | ||
"revocationReason": t.revocationReason, | ||
"purchaseDate": t.purchaseDate, | ||
"signedDate": t.signedDate, | ||
"webOrderLineItemID": t.webOrderLineItemID | ||
] | ||
} | ||
|
||
func serialize(_ ot: Transaction.OfferType?) -> String? { | ||
guard let ot = ot else {return nil} | ||
switch ot { | ||
case .promotional: return "promotional" | ||
case .introductory: return "introductory" | ||
case .code: return "code" | ||
default: | ||
return nil | ||
} | ||
} | ||
func serialize(_ ot: Transaction.OwnershipType?) -> String? { | ||
guard let ot = ot else {return nil} | ||
switch ot { | ||
case .purchased: return "purchased" | ||
case .familyShared: return "familyShared" | ||
default: | ||
return nil | ||
} | ||
} | ||
func serialize(_ pt: Product.ProductType?) -> String? { | ||
guard let pt = pt else {return nil} | ||
switch pt { | ||
case .autoRenewable: return "autoRenewable" | ||
case .consumable: return "consumable" | ||
case .nonConsumable: return "nonConsumable" | ||
case .nonRenewable: return "nonRenewable" | ||
default: | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// IapTypes.swift | ||
// RNIap | ||
// | ||
// Created by Aguilar Andres on 8/18/22. | ||
// | ||
|
||
import Foundation | ||
import StoreKit | ||
|
||
typealias RNIapIosPromise = (RCTPromiseResolveBlock, RCTPromiseRejectBlock) | ||
|
||
struct ProductOrError { | ||
let product: Product? | ||
let error: Error? | ||
} | ||
|
||
public enum StoreError: Error { | ||
case failedVerification | ||
} | ||
|
||
enum IapErrors: String, CaseIterable { | ||
case E_UNKNOWN = "E_UNKNOWN" | ||
case E_SERVICE_ERROR = "E_SERVICE_ERROR" | ||
case E_USER_CANCELLED = "E_USER_CANCELLED" | ||
case E_USER_ERROR = "E_USER_ERROR" | ||
case E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE" | ||
case E_REMOTE_ERROR = "E_REMOTE_ERROR" | ||
case E_NETWORK_ERROR = "E_NETWORK_ERROR" | ||
case E_RECEIPT_FAILED = "E_RECEIPT_FAILED" | ||
case E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED" | ||
case E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR" | ||
case E_PURCHASE_ERROR = "E_PURCHASE_ERROR" | ||
case E_SYNC_ERROR = "E_SYNC_ERROR" | ||
case E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT" | ||
func asInt() -> Int { | ||
return IapErrors.allCases.firstIndex(of: self)! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// IapUtils.swift | ||
// RNIap | ||
// | ||
// Created by Aguilar Andres on 8/15/22. | ||
// | ||
|
||
import Foundation | ||
import StoreKit | ||
|
||
public func debugMessage(_ object: Any...) { | ||
#if DEBUG | ||
for item in object { | ||
print("[react-native-iap] \(item)") | ||
} | ||
#endif | ||
} | ||
|
||
func checkVerified<T>(_ result: VerificationResult<T>) throws -> T { | ||
// Check whether the JWS passes StoreKit verification. | ||
switch result { | ||
case .unverified: | ||
// StoreKit parses the JWS, but it fails verification. | ||
throw StoreError.failedVerification | ||
|
||
case .verified(let safe): | ||
// The result is verified. Return the unwrapped value. | ||
return safe | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.