Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
liberty
tunnel
liberty-tunnel-client-library-apple
Commits
81a2f8e2
Commit
81a2f8e2
authored
Aug 14, 2019
by
Jose Blaya
Browse files
Stop the transaction purchase if sandbox receipt
parent
14a899c2
Changes
5
Hide whitespace changes
Inline
Side-by-side
PIALibrary/Resources/UI/iOS/en.lproj/Signup.strings
View file @
81a2f8e2
...
...
@@ -21,6 +21,7 @@
"failure.vc_title" = "Sign-up failed";
"failure.title" = "Account creation failed";
"failure.message" = "We're unable to create an account at this time. Please try again later. Reopening the app will re-attempt to create an account.";
"failure.purchase.sandbox.message" = "The selected sandbox subscription is not available in production.";
"failure.redeem.invalid.title" = "Invalid card PIN";
"failure.redeem.invalid.message" = "Looks like you entered an invalid card PIN. Please try again.";
"failure.redeem.claimed.title" = "Card claimed already";
...
...
PIALibrary/Sources/Library/Account/DefaultAccountProvider.swift
View file @
81a2f8e2
...
...
@@ -372,50 +372,40 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
accessedDatabase
.
plain
.
lastSignupEmail
=
request
.
email
webServices
.
signup
(
with
:
signup
)
{
[
weak
self
]
(
credentials
,
error
)
in
webServices
.
signup
(
with
:
signup
)
{
(
credentials
,
error
)
in
if
let
urlError
=
error
as?
URLError
,
(
urlError
.
code
==
.
notConnectedToInternet
)
{
callback
?(
nil
,
ClientError
.
internetUnreachable
)
return
}
guard
let
credentials
=
credentials
else
{
// If bad Receipt and purchases are not available, remove and clean the transaction from the queue
if
error
as?
ClientError
==
.
badReceipt
,
!
Client
.
configuration
.
arePurchasesAvailable
()
{
self
?
.
finishTransactions
(
successfully
:
false
)
}
callback
?(
nil
,
error
)
return
}
if
let
transaction
=
request
.
transaction
{
// Transaction is a new purchase
self
?
.
accessedStore
.
finishTransaction
(
transaction
,
success
:
true
)
}
else
{
// Transaction has been recovered
self
?
.
finishTransactions
(
successfully
:
true
)
self
.
accessedStore
.
finishTransaction
(
transaction
,
success
:
true
)
}
self
?
.
accessedDatabase
.
plain
.
lastSignupEmail
=
nil
self
?
.
accessedDatabase
.
secure
.
setPublicUsername
(
credentials
.
username
)
self
?
.
accessedDatabase
.
secure
.
setPassword
(
credentials
.
password
,
for
:
credentials
.
username
)
self
.
accessedDatabase
.
plain
.
lastSignupEmail
=
nil
self
.
accessedDatabase
.
secure
.
setPublicUsername
(
credentials
.
username
)
self
.
accessedDatabase
.
secure
.
setPassword
(
credentials
.
password
,
for
:
credentials
.
username
)
self
?
.
webServices
.
token
(
credentials
:
credentials
)
{
[
weak
self
]
(
token
,
error
)
in
self
.
webServices
.
token
(
credentials
:
credentials
)
{
(
token
,
error
)
in
guard
let
token
=
token
else
{
callback
?(
nil
,
error
)
return
}
self
?
.
updateDatabaseWith
(
token
,
self
.
updateDatabaseWith
(
token
,
andUsername
:
credentials
.
username
)
self
?
.
webServices
.
info
(
token
:
token
)
{
[
weak
self
]
(
accountInfo
,
error
)
in
self
.
webServices
.
info
(
token
:
token
)
{
(
accountInfo
,
error
)
in
guard
let
accountInfo
=
accountInfo
else
{
callback
?(
nil
,
error
)
return
}
//Save after confirm the login was successful.
self
?
.
accessedDatabase
.
plain
.
accountInfo
=
accountInfo
self
.
accessedDatabase
.
plain
.
accountInfo
=
accountInfo
let
user
=
UserAccount
(
credentials
:
credentials
,
info
:
nil
)
Macros
.
postNotification
(
.
PIAAccountDidSignup
,
[
...
...
@@ -428,16 +418,6 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
}
private
func
finishTransactions
(
successfully
:
Bool
)
{
if
let
products
=
self
.
accessedStore
.
availableProducts
{
for
product
in
products
{
if
let
transaction
=
self
.
accessedStore
.
uncreditedTransaction
(
for
:
product
)
{
self
.
accessedStore
.
finishTransaction
(
transaction
,
success
:
successfully
)
}
}
}
}
func
redeem
(
with
request
:
RedeemRequest
,
_
callback
:
((
UserAccount
?,
Error
?)
->
Void
)?)
{
guard
!
isLoggedIn
else
{
...
...
@@ -535,29 +515,22 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
return
}
webServices
.
processPayment
(
credentials
:
user
.
credentials
,
request
:
payment
)
{
[
weak
self
]
(
error
)
in
if
let
error
=
error
{
// If bad Receipt and purchases are not available, remove and clean the transaction from the queue
if
error
as?
ClientError
==
.
badReceipt
,
let
transaction
=
request
.
transaction
,
!
Client
.
configuration
.
arePurchasesAvailable
()
{
self
?
.
finishTransactions
(
successfully
:
false
)
}
webServices
.
processPayment
(
credentials
:
user
.
credentials
,
request
:
payment
)
{
(
error
)
in
if
let
_
=
error
{
callback
?(
nil
,
error
)
return
}
if
let
transaction
=
request
.
transaction
{
self
?
.
accessedStore
.
finishTransaction
(
transaction
,
success
:
true
)
self
.
accessedStore
.
finishTransaction
(
transaction
,
success
:
true
)
}
Macros
.
postNotification
(
.
PIAAccountDidRenew
)
self
?
.
webServices
.
info
(
token
:
token
)
{
[
weak
self
]
(
accountInfo
,
error
)
in
self
.
webServices
.
info
(
token
:
token
)
{
(
accountInfo
,
error
)
in
guard
let
newAccountInfo
=
accountInfo
else
{
callback
?(
nil
,
nil
)
return
}
self
?
.
accessedDatabase
.
plain
.
accountInfo
=
newAccountInfo
self
.
accessedDatabase
.
plain
.
accountInfo
=
newAccountInfo
let
user
=
UserAccount
(
credentials
:
user
.
credentials
,
info
:
newAccountInfo
)
Macros
.
postNotification
(
.
PIAAccountDidRefresh
,
[
...
...
PIALibrary/Sources/Library/ClientError.swift
View file @
81a2f8e2
...
...
@@ -60,5 +60,20 @@ public enum ClientError: String, Error {
/// Invalid parameter
case
invalidParameter
/// The selected sandbox subscription is not available in production.
case
sandboxPurchase
#endif
}
extension
ClientError
:
LocalizedError
{
public
var
errorDescription
:
String
?
{
switch
self
{
case
.
sandboxPurchase
:
return
NSLocalizedString
(
L10n
.
Signup
.
Failure
.
Purchase
.
Sandbox
.
message
,
comment
:
L10n
.
Signup
.
Failure
.
Purchase
.
Sandbox
.
message
)
default
:
return
nil
}
}
}
PIALibrary/Sources/Library/InApp/AppStoreProvider.swift
View file @
81a2f8e2
...
...
@@ -84,6 +84,11 @@ class AppStoreProvider: NSObject, InAppProvider {
log
.
warning
(
"Purchase in progress"
)
return
}
if
!
Client
.
configuration
.
arePurchasesAvailable
()
{
log
.
warning
(
"Purchases not available in sandbox"
)
callback
?(
nil
,
ClientError
.
sandboxPurchase
)
return
}
let
payment
=
SKPayment
(
product
:
product
.
native
as!
SKProduct
)
log
.
debug
(
"Purchasing product with identifier:
\(
payment
.
productIdentifier
)
"
)
...
...
PIALibrary/Sources/UI/iOS/SwiftGen+Strings.swift
View file @
81a2f8e2
...
...
@@ -21,6 +21,12 @@ internal enum L10n {
internal
static
let
title
=
L10n
.
tr
(
"Signup"
,
"failure.title"
)
/// Sign-up failed
internal
static
let
vcTitle
=
L10n
.
tr
(
"Signup"
,
"failure.vc_title"
)
internal
enum
Purchase
{
internal
enum
Sandbox
{
/// The selected sandbox subscription is not available in production.
internal
static
let
message
=
L10n
.
tr
(
"Signup"
,
"failure.purchase.sandbox.message"
)
}
}
internal
enum
Redeem
{
internal
enum
Claimed
{
/// Looks like this card has already been claimed by another account. You can try entering a different PIN.
...
...
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