bizz84 / bizz84/SwiftyStoreKit

Convert `Purchase` to `PurchaseDetails` and vice versa

Open
#352 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
6.7k
Forks
801
PR merge metrics
No merged PRs in 30d

Description

### Platform

- [x] iOS
- [ ] macOS
- [ ] tvOS

### Environment

- [ ] Sandbox
- [x] Production

### Version
0.13.1

### Related issues
#202
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170130/031119.html

## Report
### Issue summary
Recently I've updated SwiftyStoreKit from 0.7.1 to 0.13.1 and tried to fix all API-breaking issues. Except substituting `Product` with `Purchase` or `PurchaseDetails` for some cases (which is for example when using PurchaseResult for SwiftyStoreKit.purchaseProduct), I am facing issues with converting these values from one to another.

### What did you expect to happen
I'd like to convert `PurchaseDetails` object received from PurchaseResult into `Purchase` object by using default public struct's initialiser or by using some convenience method. However, in the current version of Swift it's impossible.
```
let product = Purchase(productId: purchaseDetails.productId,
quantity: purchaseDetails.quantity,
transaction: purchaseDetails.transaction,
originalTransaction: purchaseDetails.originalTransaction,
needsFinishTransaction: purchaseDetails.needsFinishTransaction)
```
### What happened instead
`'Purchase' initializer is inaccessible due to 'internal' protection level`

As a temporary solution had to override the init in extension:
```
extension Purchase {
init(productId: String, quantity: Int, transaction: PaymentTransaction, originalTransaction: PaymentTransaction?, needsFinishTransaction: Bool) {
self.productId = productId
self.quantity = quantity
self.transaction = transaction
self.originalTransaction = originalTransaction
self.needsFinishTransaction = needsFinishTransaction
}
}
```
but if you can declare it in the framework itself it'll be a bit more convenient.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.