Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
f1a7d6bc
Commit
f1a7d6bc
authored
May 19, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOS-74: log purchases and revenue.
parent
b1ace4d2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
3 deletions
+35
-3
1Weather/InApps/OLInAppStoreManager.swift
+35
-3
No files found.
1Weather/InApps/OLInAppStoreManager.swift
View file @
f1a7d6bc
...
...
@@ -8,6 +8,7 @@
import
UIKit
import
StoreKit
import
AppsFlyerLib
// Ported from ObjC
...
...
@@ -40,6 +41,7 @@ class OLInAppStoreManager: NSObject {
}
var
currentRequest
:
SKProductsRequest
?
var
currentProduct
:
SKProduct
?
// MARK: - public methods
func
attemptPurchase
(
forProductId
productId
:
String
)
{
...
...
@@ -89,6 +91,7 @@ extension OLInAppStoreManager: SKProductsRequestDelegate {
}
}
if
let
validProduct
=
validProduct
{
currentProduct
=
validProduct
let
payment
=
SKPayment
(
product
:
validProduct
)
delegate
?
.
inAppStoreManager
(
self
,
purchaseWillBeAdded
:
payment
)
SKPaymentQueue
.
default
()
.
add
(
self
)
...
...
@@ -110,13 +113,43 @@ extension OLInAppStoreManager: SKPaymentTransactionObserver {
switch
transaction
.
transactionState
{
case
.
purchased
:
delegate
?
.
inAppStoreManager
(
self
,
purchaseCompletedForProductId
:
transaction
.
payment
.
productIdentifier
)
if
let
currentProduct
=
self
.
currentProduct
,
currentProduct
.
productIdentifier
==
transaction
.
payment
.
productIdentifier
{
if
let
currencyCode
=
currentProduct
.
priceLocale
.
currencyCode
{
#if DEBUG
AppsFlyerLib
.
shared
()
.
useReceiptValidationSandbox
=
true
#endif
AppsFlyerLib
.
shared
()
.
validateAndLog
(
inAppPurchase
:
currentProduct
.
productIdentifier
,
price
:
currentProduct
.
price
.
stringValue
,
currency
:
currencyCode
,
transactionId
:
transaction
.
transactionIdentifier
,
additionalParameters
:
nil
,
success
:
{
[
weak
self
]
in
guard
let
dictionary
=
$0
as?
[
String
:
Any
]
else
{
self
?
.
log
.
info
(
"AppsFlyer verified purchase."
)
return
}
self
?
.
log
.
info
(
"AppsFlyer verified purchase:
\(
dictionary
)
"
)
},
failure
:
{
[
weak
self
]
error
,
result
in
self
?
.
log
.
error
(
"AppsFlyer purchase verification failed: error:
\(
String
(
describing
:
error
)
)
, result:
\(
String
(
describing
:
result
)
)
"
)
})
}
else
{
log
.
error
(
"AppsFlyer purchase event: currency not found."
)
}
}
else
{
log
.
error
(
"AppsFlyer purchase event: could find matching product."
)
}
SKPaymentQueue
.
default
()
.
finishTransaction
(
transaction
)
case
.
failed
:
if
let
error
=
transaction
.
error
{
log
.
error
(
"
SKPaymentTransactionStateFailedError
:
\(
error
)
"
)
log
.
error
(
"
Transaction failed
:
\(
error
)
"
)
}
else
{
log
.
error
(
"
SKPaymentTransactionStateFailedError
: unknown error"
)
log
.
error
(
"
Transaction failed
: unknown error"
)
}
delegate
?
.
inAppStoreManager
(
self
,
purchaseFailedFor
:
transaction
)
SKPaymentQueue
.
default
()
.
finishTransaction
(
transaction
)
...
...
@@ -156,7 +189,6 @@ extension OLInAppStoreManager: SKPaymentTransactionObserver {
// MARK: - SKRequestDelegate
extension
OLInAppStoreManager
:
SKRequestDelegate
{
func
requestDidFinish
(
_
request
:
SKRequest
)
{
log
.
debug
(
"requestDidFinish"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment