diff --git a/Docs/Authentication.md b/Docs/Authentication.md
index 29c3155..23ecc40 100644
--- a/Docs/Authentication.md
+++ b/Docs/Authentication.md
@@ -19,10 +19,9 @@ Initialise the library using `AppDelegate`. You can set the `ClientId`, `SecretI
ReloadlySDKSecretId
PUT_YOUR_RELOADLY_CLIENT_SECRET_HERE
ReloadlySDKEnvironment
-sandbox
+airtimeSandbox
```
-
```swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -63,7 +62,7 @@ To enable API default logging at `info` level, please change log level during SD
You can switch the backendEnvironment that the SDK integracts with; by default the prouction environment backend is used.
```swift
- ReloadlyAuthentication.shared.configure(service: AuthenticationService(backendEnvironment: .sandbox), logLevel: .info)
+ ReloadlyAuthentication.shared.configure(service: AuthenticationService(backendEnvironment: .airtimeSandbox), logLevel: .info)
```
## Customizing The API Client Instance
@@ -82,11 +81,11 @@ Connect and read timeouts can be configured globally:
let proxyConfiguratorWithCredentials = ProxyConfigurator(hostUrl: "url", port: 8043, username: "username", password: "password")
ReloadlyAuthentication.shared.configure(with: "id",
clientSecret: "secret",
- service: AuthenticationService(backendEnvironment: .sandbox),
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox),
logLevel: .info, proxyConfiguration: proxyConfiguratorWithCredentials)
```
-Also username and password can be nil to use proxy without credentials.
+Also username and password can be nil to use proxy without credentials.
Note that, while providing the `clientId` and `clientSecret` is supported as shown below, it is generallly discouraged. Make use of the plist instead to specify the clientId and clientSecret.
@@ -99,7 +98,7 @@ You can disable this behavior if you prefer:
```swift
ReloadlyAuthentication.shared.configure(with: "id",
clientSecret: "secret",
- service: AuthenticationService(backendEnvironment: .sandbox),
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox),
logLevel: .info, useTelemetry: false)
```
diff --git a/Docs/GiftcardsSDK.md b/Docs/GiftcardsSDK.md
new file mode 100644
index 0000000..ee9579b
--- /dev/null
+++ b/Docs/GiftcardsSDK.md
@@ -0,0 +1,156 @@
+# Giftcards SDK
+
+Gift cards are an awesome way to send and receive value in a digital economy that is fast becoming the future. Reloadly's GiftCard SDK connects you to over 200 gift cards that can be used both locally and internationally across 140+ countries.
+This enables you to purchase gift cards for both commercial and personal reasons. Some of the data you will need are your access token and the brand details of the gift card.
+This documentation contains a reference to each endpoint in the GiftCard API. You can check it out to learn more about how they work.
+
+
+## Get all products
+
+```java
+ReloadlyGiftcard.shared.getAllProducts() { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+
+## Get product by ID
+
+You can access the details of a particular gift card by making a request with that gift card's product ID
+
+```swift
+
+ReloadlyGiftcard.shared.getProduct(by: Int) { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+
+## Get products by ISO Code
+
+You can retrieve details of every gift card product that is available in a country
+
+```swift
+
+ReloadlyGiftcard.shared.getProductByISO(countryCode: String) { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+## Get all redeem instructions
+
+Redeem instructions are useful for retrieving the value of a gift card. The redeem instructions provides details on how to redeem every gift card product made available by Reloadly.
+
+```swift
+
+ReloadlyGiftcard.shared.redeemInstruction() { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+## Get redeem instructions by brand ID
+
+Retrieve the redeem instructions for a particular gift card brand
+
+```swift
+
+ReloadlyGiftcard.shared.redeemInstruction(by id: Int) { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+## Get all discounts
+
+Fetch data of every gift card that has an available discount at the point of purchase
+
+```swift
+
+ReloadlyGiftcard.shared.allTransactions() { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+## Get discount by product ID
+
+Get the details of an active discount on a particular gift card product
+
+```swift
+
+ReloadlyGiftcard.shared.transaction(by id: Int) { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+## Order a gift card
+
+You can make a request to purchase any of the gift card products made available via Reloadly
+
+```swift
+
+ReloadlyGiftcard.shared.orderGiftcard(with productId: Int,
+ countryCode: String,
+ quantity: Int,
+ unitPrice: Double,
+ customIdentifier: String,
+ senderName: String,
+ recipientEmail: String) { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
+
+## Get a redeem code
+
+Retrieve details of an already purchased gift card's redeem code.
+Note that in some cases, a purchased gift card's details may not be readily available due to the transaction still being processed. In this case, you can track the transaction details using the Get Transaction by ID endpoint.
+
+```swift
+
+ReloadlyGiftcard.shared.redeemCode(by transactionId: Int) { result in
+ switch result {
+ case .success(let result):
+ print(result)
+ case .failure(let error):
+ print(error)
+ }
+ }
+```
diff --git a/Docs/Sample_code.md b/Docs/Sample_code.md
index ed5a570..2629337 100644
--- a/Docs/Sample_code.md
+++ b/Docs/Sample_code.md
@@ -13,3 +13,7 @@
* [Promotion Operations](https://github.com/Reloadly/reloadly-sdk-ios/blob/main/Docs/Promotion.md)
* [Report Operations](https://github.com/Reloadly/reloadly-sdk-ios/blob/main/Docs/Report.md)
* [Topup Operations](https://github.com/Reloadly/reloadly-sdk-ios/blob/main/Docs/Topup.md)
+
+## GiftCard SDK
+
+* [GiftcardsSDK](https://github.com/Reloadly/reloadly-sdk-ios/blob/main/Docs/GiftcardsSDK.md)
diff --git a/Example/Podfile b/Example/Podfile
index b2be985..6da5c31 100644
--- a/Example/Podfile
+++ b/Example/Podfile
@@ -4,6 +4,7 @@ platform :ios, '10.0'
target 'ReloadlyAuthentication_Example' do
pod 'ReloadlySDK/Airtime', :path => '../'
+ pod 'ReloadlySDK/GiftCard', :path => '../'
target 'ReloadlyAuthentication_Tests' do
inherit! :search_paths
diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj
index f0abc53..60fbf7b 100644
--- a/Example/Pods/Pods.xcodeproj/project.pbxproj
+++ b/Example/Pods/Pods.xcodeproj/project.pbxproj
@@ -38,6 +38,12 @@
A4A680ABC25F8C9F730EA4BAEB52AEEC /* ReloadlySDK-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = EC41314C2A07D306BFC79E3E21C06C11 /* ReloadlySDK-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; };
D24AB5E778196E2BD8B6D9E376596715 /* Pods-ReloadlyAuthentication_Tests-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 6827B24491E1DAA988C17129B8123E55 /* Pods-ReloadlyAuthentication_Tests-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; };
EA87991AE9CC00F0A64D467E852AFDC1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73010CC983E3809BECEE5348DA1BB8C6 /* Foundation.framework */; };
+ F331A5FD2790A35B00C3B416 /* SortModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F331A5FC2790A35B00C3B416 /* SortModel.swift */; };
+ F34FC6C22798739200B2CF05 /* RecipientPhoneDetailsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F34FC6C12798739100B2CF05 /* RecipientPhoneDetailsModel.swift */; };
+ F3B7BE29274AD7990084A3BC /* ReloadlyGiftcard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3B7BE28274AD7990084A3BC /* ReloadlyGiftcard.swift */; };
+ F3BDE029274BF552006983AB /* ProductsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDE028274BF552006983AB /* ProductsModel.swift */; };
+ F3BDE02D274BFE0E006983AB /* OrderGiftcardModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDE02C274BFE0E006983AB /* OrderGiftcardModel.swift */; };
+ F3BDE02F274BFF2D006983AB /* RedeemCodeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDE02E274BFF2D006983AB /* RedeemCodeModel.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -110,6 +116,12 @@
EA173E0F1655BBE1D5D6DEE4B8F8828C /* Pods-ReloadlyAuthentication_Example-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-ReloadlyAuthentication_Example-frameworks.sh"; sourceTree = ""; };
EBE6EFD91CA2F531C1552AFA036FE598 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; };
EC41314C2A07D306BFC79E3E21C06C11 /* ReloadlySDK-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "ReloadlySDK-umbrella.h"; sourceTree = ""; };
+ F331A5FC2790A35B00C3B416 /* SortModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortModel.swift; sourceTree = ""; };
+ F34FC6C12798739100B2CF05 /* RecipientPhoneDetailsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientPhoneDetailsModel.swift; sourceTree = ""; };
+ F3B7BE28274AD7990084A3BC /* ReloadlyGiftcard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadlyGiftcard.swift; sourceTree = ""; };
+ F3BDE028274BF552006983AB /* ProductsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsModel.swift; sourceTree = ""; };
+ F3BDE02C274BFE0E006983AB /* OrderGiftcardModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderGiftcardModel.swift; sourceTree = ""; };
+ F3BDE02E274BFF2D006983AB /* RedeemCodeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedeemCodeModel.swift; sourceTree = ""; };
F77FF3918786364D682C453189BEC190 /* Pods_ReloadlyAuthentication_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReloadlyAuthentication_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FECCC601891B10E1F805EE8C1A0DDCDC /* Pods-ReloadlyAuthentication_Example-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-ReloadlyAuthentication_Example-dummy.m"; sourceTree = ""; };
/* End PBXFileReference section */
@@ -145,7 +157,6 @@
1A7743BA26033FC700D34144 /* ReloadlyAirtime */ = {
isa = PBXGroup;
children = (
- 1A7743BB26033FC700D34144 /* Models */,
1A7743C326033FC700D34144 /* ReloadlyAirtime+Promotions.swift */,
1A7743C426033FC700D34144 /* ReloadlyAirtime.swift */,
1A7743C526033FC700D34144 /* ReloadlyAirtime+Operators.swift */,
@@ -154,20 +165,6 @@
path = ReloadlySDK/Classes/ReloadlyAirtime;
sourceTree = "";
};
- 1A7743BB26033FC700D34144 /* Models */ = {
- isa = PBXGroup;
- children = (
- 1A7743BC26033FC700D34144 /* BalanceModel.swift */,
- 1A7743BD26033FC700D34144 /* CountryModel.swift */,
- 1A7743BE26033FC700D34144 /* PhoneModel.swift */,
- 1A7743BF26033FC700D34144 /* OperatorModel.swift */,
- 1A7743C026033FC700D34144 /* PromotionModel.swift */,
- 1A7743C126033FC700D34144 /* DiscountsModel.swift */,
- 1A7743C226033FC700D34144 /* TopupsModel.swift */,
- );
- path = Models;
- sourceTree = "";
- };
1A7743C826033FC700D34144 /* ReloadlyAuthentication */ = {
isa = PBXGroup;
children = (
@@ -204,6 +201,14 @@
children = (
1A7743D426033FC700D34144 /* ErrorModel.swift */,
1A7743D526033FC700D34144 /* OAuth2Token.swift */,
+ 1A7743BD26033FC700D34144 /* CountryModel.swift */,
+ 1A7743BC26033FC700D34144 /* BalanceModel.swift */,
+ 1A7743BE26033FC700D34144 /* PhoneModel.swift */,
+ 1A7743BF26033FC700D34144 /* OperatorModel.swift */,
+ 1A7743C026033FC700D34144 /* PromotionModel.swift */,
+ 1A7743C126033FC700D34144 /* DiscountsModel.swift */,
+ 1A7743C226033FC700D34144 /* TopupsModel.swift */,
+ F331A5FC2790A35B00C3B416 /* SortModel.swift */,
);
path = Models;
sourceTree = "";
@@ -294,6 +299,7 @@
children = (
1A7743BA26033FC700D34144 /* ReloadlyAirtime */,
1A7743C826033FC700D34144 /* ReloadlyAuthentication */,
+ F3B7BE27274AD7590084A3BC /* ReloadlyGiftcard */,
962E6B909208D6C753A0977BBC81F2D5 /* Pod */,
A1456B760C0CF163545F9AC1449EE3A8 /* Support Files */,
);
@@ -344,6 +350,27 @@
name = "Development Pods";
sourceTree = "";
};
+ F3B7BE27274AD7590084A3BC /* ReloadlyGiftcard */ = {
+ isa = PBXGroup;
+ children = (
+ F3B7BE28274AD7990084A3BC /* ReloadlyGiftcard.swift */,
+ F3BDE030274BFFB2006983AB /* Models */,
+ );
+ name = ReloadlyGiftcard;
+ path = ReloadlySDK/Classes/ReloadlyGiftcard;
+ sourceTree = "";
+ };
+ F3BDE030274BFFB2006983AB /* Models */ = {
+ isa = PBXGroup;
+ children = (
+ F3BDE028274BF552006983AB /* ProductsModel.swift */,
+ F3BDE02C274BFE0E006983AB /* OrderGiftcardModel.swift */,
+ F3BDE02E274BFF2D006983AB /* RedeemCodeModel.swift */,
+ F34FC6C12798739100B2CF05 /* RecipientPhoneDetailsModel.swift */,
+ );
+ path = Models;
+ sourceTree = "";
+ };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -437,7 +464,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1100;
- LastUpgradeCheck = 1100;
+ LastUpgradeCheck = 1310;
};
buildConfigurationList = 4821239608C13582E20E6DA73FD5F1F9 /* Build configuration list for PBXProject "Pods" */;
compatibilityVersion = "Xcode 3.2";
@@ -505,15 +532,20 @@
buildActionMask = 2147483647;
files = (
1A7743EF26033FC800D34144 /* ErrorModel.swift in Sources */,
+ F3B7BE29274AD7990084A3BC /* ReloadlyGiftcard.swift in Sources */,
1A7743E226033FC700D34144 /* TopupsModel.swift in Sources */,
1A7743DC26033FC700D34144 /* BalanceModel.swift in Sources */,
1A7743DF26033FC700D34144 /* OperatorModel.swift in Sources */,
1A7743F526033FC800D34144 /* AuthenticationBackendEnvironment.swift in Sources */,
+ F3BDE029274BF552006983AB /* ProductsModel.swift in Sources */,
30802B8A10C02A81289543FC17C784FB /* ReloadlySDK-dummy.m in Sources */,
1A7743E126033FC700D34144 /* DiscountsModel.swift in Sources */,
1A7743DE26033FC700D34144 /* PhoneModel.swift in Sources */,
+ F3BDE02F274BFF2D006983AB /* RedeemCodeModel.swift in Sources */,
+ F331A5FD2790A35B00C3B416 /* SortModel.swift in Sources */,
1A7743E326033FC700D34144 /* ReloadlyAirtime+Promotions.swift in Sources */,
1A7743DD26033FC700D34144 /* CountryModel.swift in Sources */,
+ F34FC6C22798739200B2CF05 /* RecipientPhoneDetailsModel.swift in Sources */,
1A7743E026033FC700D34144 /* PromotionModel.swift in Sources */,
1A7743EE26033FC800D34144 /* NetworkManager.swift in Sources */,
1A7743F326033FC800D34144 /* ProxyConfigurator.swift in Sources */,
@@ -525,6 +557,7 @@
1A7743E526033FC700D34144 /* ReloadlyAirtime+Operators.swift in Sources */,
1A7743F126033FC800D34144 /* ReloadlyAuthentication.swift in Sources */,
1A7743EA26033FC800D34144 /* Formatter.swift in Sources */,
+ F3BDE02D274BFE0E006983AB /* OrderGiftcardModel.swift in Sources */,
1A7743E426033FC700D34144 /* ReloadlyAirtime.swift in Sources */,
1A7743F026033FC800D34144 /* OAuth2Token.swift in Sources */,
);
@@ -564,7 +597,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Tests/Pods-ReloadlyAuthentication_Tests-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Tests/Pods-ReloadlyAuthentication_Tests.modulemap";
@@ -598,7 +631,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Example/Pods-ReloadlyAuthentication_Example-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Example/Pods-ReloadlyAuthentication_Example.modulemap";
@@ -666,7 +699,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -693,7 +726,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Tests/Pods-ReloadlyAuthentication_Tests-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Tests/Pods-ReloadlyAuthentication_Tests.modulemap";
@@ -726,7 +759,7 @@
GCC_PREFIX_HEADER = "Target Support Files/ReloadlySDK/ReloadlySDK-prefix.pch";
INFOPLIST_FILE = "Target Support Files/ReloadlySDK/ReloadlySDK-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MODULEMAP_FILE = "Target Support Files/ReloadlySDK/ReloadlySDK.modulemap";
PRODUCT_MODULE_NAME = ReloadlySDK;
@@ -758,7 +791,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Example/Pods-ReloadlyAuthentication_Example-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "Target Support Files/Pods-ReloadlyAuthentication_Example/Pods-ReloadlyAuthentication_Example.modulemap";
@@ -828,7 +861,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
@@ -857,7 +890,7 @@
GCC_PREFIX_HEADER = "Target Support Files/ReloadlySDK/ReloadlySDK-prefix.pch";
INFOPLIST_FILE = "Target Support Files/ReloadlySDK/ReloadlySDK-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MODULEMAP_FILE = "Target Support Files/ReloadlySDK/ReloadlySDK.modulemap";
PRODUCT_MODULE_NAME = ReloadlySDK;
diff --git a/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/Pods-ReloadlyAuthentication_Example.xcscheme b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/Pods-ReloadlyAuthentication_Example.xcscheme
new file mode 100644
index 0000000..a195fa4
--- /dev/null
+++ b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/Pods-ReloadlyAuthentication_Example.xcscheme
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/Pods-ReloadlyAuthentication_Tests.xcscheme b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/Pods-ReloadlyAuthentication_Tests.xcscheme
new file mode 100644
index 0000000..0a77550
--- /dev/null
+++ b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/Pods-ReloadlyAuthentication_Tests.xcscheme
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/ReloadlySDK.xcscheme b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/ReloadlySDK.xcscheme
new file mode 100644
index 0000000..ad3cc38
--- /dev/null
+++ b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/ReloadlySDK.xcscheme
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/xcschememanagement.plist b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..ef0f153
--- /dev/null
+++ b/Example/Pods/Pods.xcodeproj/xcuserdata/tarik.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,26 @@
+
+
+
+
+ SchemeUserState
+
+ Pods-ReloadlyAuthentication_Example.xcscheme
+
+ isShown
+
+
+ Pods-ReloadlyAuthentication_Tests.xcscheme
+
+ isShown
+
+
+ ReloadlySDK.xcscheme
+
+ isShown
+
+
+
+ SuppressBuildableAutocreation
+
+
+
diff --git a/Example/ReloadlyAuthentication.xcodeproj/project.pbxproj b/Example/ReloadlyAuthentication.xcodeproj/project.pbxproj
index 8d90c3a..b891d32 100644
--- a/Example/ReloadlyAuthentication.xcodeproj/project.pbxproj
+++ b/Example/ReloadlyAuthentication.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
607FACEC1AFB9204008FA782 /* AutenticationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* AutenticationTest.swift */; };
A1BAE5131423FAF995F164B3 /* Pods_ReloadlyAuthentication_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFDB84F883D67EF72541412B /* Pods_ReloadlyAuthentication_Example.framework */; };
+ F3BDE034274C0152006983AB /* ReloadlyGiftcardTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BDE033274C0152006983AB /* ReloadlyGiftcardTest.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -51,6 +52,7 @@
67341B0D82C5099B1167DA22 /* Pods-ReloadlyAuthentication_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReloadlyAuthentication_Tests.release.xcconfig"; path = "Target Support Files/Pods-ReloadlyAuthentication_Tests/Pods-ReloadlyAuthentication_Tests.release.xcconfig"; sourceTree = ""; };
A4FA8A87922145E14255079E /* Pods-ReloadlyAuthentication_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReloadlyAuthentication_Tests.debug.xcconfig"; path = "Target Support Files/Pods-ReloadlyAuthentication_Tests/Pods-ReloadlyAuthentication_Tests.debug.xcconfig"; sourceTree = ""; };
CFDB84F883D67EF72541412B /* Pods_ReloadlyAuthentication_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReloadlyAuthentication_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ F3BDE033274C0152006983AB /* ReloadlyGiftcardTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadlyGiftcardTest.swift; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -133,6 +135,7 @@
607FACEB1AFB9204008FA782 /* AutenticationTest.swift */,
1A4B7B9D2604EAFA004A00AA /* DemoAppTest.swift */,
1A7744062603521800D34144 /* ReloadlyAirtimeTest.swift */,
+ F3BDE033274C0152006983AB /* ReloadlyGiftcardTest.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
path = Tests;
@@ -222,7 +225,7 @@
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
- LastSwiftMigration = 1240;
+ LastSwiftMigration = 1310;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
@@ -346,6 +349,7 @@
buildActionMask = 2147483647;
files = (
607FACEC1AFB9204008FA782 /* AutenticationTest.swift in Sources */,
+ F3BDE034274C0152006983AB /* ReloadlyGiftcardTest.swift in Sources */,
1A77440F2603530700D34144 /* ReloadlyAirtimeTest.swift in Sources */,
1A4B7B9E2604EAFA004A00AA /* DemoAppTest.swift in Sources */,
);
@@ -523,6 +527,7 @@
baseConfigurationReference = A4FA8A87922145E14255079E /* Pods-ReloadlyAuthentication_Tests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
+ CLANG_ENABLE_MODULES = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
@@ -535,6 +540,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReloadlyAuthentication_Example.app/ReloadlyAuthentication_Example";
@@ -546,6 +552,7 @@
baseConfigurationReference = 67341B0D82C5099B1167DA22 /* Pods-ReloadlyAuthentication_Tests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
+ CLANG_ENABLE_MODULES = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
diff --git a/Example/ReloadlyAuthentication.xcworkspace/xcuserdata/tarik.xcuserdatad/UserInterfaceState.xcuserstate b/Example/ReloadlyAuthentication.xcworkspace/xcuserdata/tarik.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..39457e1
Binary files /dev/null and b/Example/ReloadlyAuthentication.xcworkspace/xcuserdata/tarik.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/Example/ReloadlyAuthentication/Info.plist b/Example/ReloadlyAuthentication/Info.plist
index e5e86d5..5002f3c 100644
--- a/Example/ReloadlyAuthentication/Info.plist
+++ b/Example/ReloadlyAuthentication/Info.plist
@@ -5,11 +5,11 @@
CFBundleDevelopmentRegion
en
ReloadlySDKClientId
-
+ CnRq3ACS1AsOYb2hnW8iEAOZq09pEPOT
ReloadlySDKSecretId
-
+ 0Q8t7n7chP-KESrM0Mauy6U3UmxGR9-ATE0k8CuLoSVk7cDF1Yz2pI7mAh5TcEg
ReloadlySDKEnvironment
- sandbox
+ giftcardSandbox
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
diff --git a/Example/Tests/AutenticationTest.swift b/Example/Tests/AutenticationTest.swift
index 8ba9757..21ca470 100644
--- a/Example/Tests/AutenticationTest.swift
+++ b/Example/Tests/AutenticationTest.swift
@@ -6,7 +6,7 @@ class AutenticationTests: XCTestCase {
super.setUp()
ReloadlyAuthentication.shared.configure(with: "NxhvFxDrXtX34VL1DLHsbQGLOPgE8qL9",
clientSecret: "c7gcNR4dOIAlmalojV35okbq--tqqVhPPr2bvcsXlmKadewvaXdRSxENwfpyFywh",
- service: AuthenticationService(backendEnvironment: .sandbox))
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox))
}
override func tearDown() {
@@ -34,7 +34,7 @@ class AutenticationTests: XCTestCase {
let proxy = ProxyConfigurator(hostUrl: "localhost", port: 80, username: "username", password: "password")
ReloadlyAuthentication.shared.configure(with: "id",
clientSecret: "id",
- service: AuthenticationService(backendEnvironment: .sandbox), logLevel: .debug, proxyConfiguration: proxy)
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox), logLevel: .debug, proxyConfiguration: proxy)
ReloadlyAuthentication.shared.requestAccessToken() { result in
switch result {
case .success(let token):
diff --git a/Example/Tests/ReloadlyAirtimeTest.swift b/Example/Tests/ReloadlyAirtimeTest.swift
index 16d4738..b9f5afd 100644
--- a/Example/Tests/ReloadlyAirtimeTest.swift
+++ b/Example/Tests/ReloadlyAirtimeTest.swift
@@ -15,7 +15,7 @@ class ReloadlyAirtimeTest: XCTestCase {
super.setUp()
ReloadlyAuthentication.shared.configure(with: "NxhvFxDrXtX34VL1DLHsbQGLOPgE8qL9",
clientSecret: "c7gcNR4dOIAlmalojV35okbq--tqqVhPPr2bvcsXlmKadewvaXdRSxENwfpyFywh",
- service: AuthenticationService(backendEnvironment: .sandbox))
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox))
ReloadlyAuthentication.shared.requestAccessToken() { result in
XCTAssertNotNil(result)
}
@@ -126,7 +126,7 @@ class ReloadlyAirtimeTest: XCTestCase {
let proxy = ProxyConfigurator(hostUrl: "localhost", port: 80, username: "username", password: "password")
ReloadlyAuthentication.shared.configure(with: "NxhvFxDrXtX34VL1DLHsbQGLOPgE8qL9",
clientSecret: "c7gcNR4dOIAlmalojV35okbq--tqqVhPPr2bvcsXlmKadewvaXdRSxENwfpyFywh",
- service: AuthenticationService(backendEnvironment: .sandbox), proxyConfiguration: proxy)
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox), proxyConfiguration: proxy)
ReloadlyAirtime.shared.getAccountBalance() { result in
XCTAssertNotNil(result)
}
@@ -136,7 +136,7 @@ class ReloadlyAirtimeTest: XCTestCase {
func testNotExpiredToken() {
ReloadlyAuthentication.shared.configure(with: "NxhvFxDrXtX34VL1DLHsbQGLOPgE8qL9",
clientSecret: "c7gcNR4dOIAlmalojV35okbq--tqqVhPPr2bvcsXlmKadewvaXdRSxENwfpyFywh",
- service: AuthenticationService(backendEnvironment: .sandbox))
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox))
ReloadlyAuthentication.shared.requestAccessToken(completionHandler: { result in
XCTAssertNotNil(result)
})
@@ -145,7 +145,7 @@ class ReloadlyAirtimeTest: XCTestCase {
func testEmptyToken() {
ReloadlyAuthentication.shared.configure(with: "",
clientSecret: "",
- service: AuthenticationService(backendEnvironment: .sandbox))
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox))
ReloadlyAuthentication.shared.requestAccessToken(completionHandler: { result in
XCTAssertNotNil(result)
})
@@ -176,8 +176,8 @@ class ReloadlyAirtimeTest: XCTestCase {
func testEnvironment() {
- let service = AuthenticationService(backendEnvironment: .production)
- service.backendEnvironment = .sandbox
+ let service = AuthenticationService(backendEnvironment: .airtimeProduction)
+ service.backendEnvironment = .airtimeSandbox
XCTAssertNotNil(service)
}
@@ -209,7 +209,7 @@ class ReloadlyAirtimeTest: XCTestCase {
func testDiscountsModel() {
- let discount = Discounts(content: [Content(percentage: 2.2, internationalPercentage: 23.21, localPercentage: 13.1, updatedAt: nil, contentOperator: nil)], pageable: Pageable(sort: Sort(unsorted: false, sorted: false, empty: false), pageNumber: 1, pageSize: 2, offset: 2, unpaged: false, paged: false), totalElements: 1, totalPages: 3, last: false, sort: Sort(unsorted: false, sorted: false, empty: false), first: false, numberOfElements: 3, size: 3, number: 3, empty: false)
+ let discount = Discounts(content: [Discount(percentage: 2.2, internationalPercentage: 23.21, localPercentage: 13.1, updatedAt: nil, contentOperator: nil)], pageable: Pageable(sort: Sort(unsorted: false, sorted: false, empty: false), pageNumber: 1, pageSize: 2, offset: 2, unpaged: false, paged: false), totalElements: 1, totalPages: 3, last: false, sort: Sort(unsorted: false, sorted: false, empty: false), first: false, numberOfElements: 3, size: 3, number: 3, empty: false)
XCTAssertEqual(2.2, discount.content.first?.percentage)
}
@@ -230,7 +230,7 @@ class ReloadlyAirtimeTest: XCTestCase {
func testRequestAuth() {
ReloadlyAuthentication.shared.configure(with: "NxhvFxDrXtX34VL1DLHsbQGLOPgE8qL9",
clientSecret: "c7gcNR4dOIAlmalojV35okbq--tqqVhPPr2bvcsXlmKadewvaXdRSxENwfpyFywh",
- service: AuthenticationService(backendEnvironment: .sandbox))
+ service: AuthenticationService(backendEnvironment: .airtimeSandbox))
ReloadlyAuthentication.shared.requestAccessToken() { result in
XCTAssertNotNil(result)
}
diff --git a/Example/Tests/ReloadlyGiftcardTest.swift b/Example/Tests/ReloadlyGiftcardTest.swift
new file mode 100644
index 0000000..0eaa12a
--- /dev/null
+++ b/Example/Tests/ReloadlyGiftcardTest.swift
@@ -0,0 +1,100 @@
+//
+// ReloadlyGiftcardTest.swift
+// ReloadlyAuthentication_Tests
+//
+// Created by Tarik on 22.11.2021.
+// Copyright © 2021 CocoaPods. All rights reserved.
+//
+
+import XCTest
+@testable import ReloadlySDK
+
+
+class ReloadlyGiftcardTest: XCTestCase {
+
+ override func setUp() {
+ super.setUp()
+ ReloadlyAuthentication.shared.configure(with: "CnRq3ACS1AsOYb2hnW8iEAOZq09pEPOT",
+ clientSecret: "0Q8t7n7chP-KESrM0Mauy6U3UmxGR9-ATE0k8CuLoSVk7cDF1Yz2pI7mAh5TcEg",
+ service: AuthenticationService(backendEnvironment: .giftcardSandbox))
+ ReloadlyAuthentication.shared.requestAccessToken() { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testGetAllProducts() {
+ ReloadlyGiftcard.shared.getAllProducts() { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testGetAllProductsWithParams() {
+ ReloadlyGiftcard.shared.getAllProducts(includeRange: true, includeFixed: true) { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testGetAllProductsWithId() {
+ ReloadlyGiftcard.shared.getProduct(by: 1) { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testRedeemCodeWithId() {
+ ReloadlyGiftcard.shared.redeemCode(by: 617) { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testDiscounts() {
+ ReloadlyGiftcard.shared.discounts() { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testDiscountsById() {
+ ReloadlyGiftcard.shared.discounts(by: 1) { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testAllTransactions() {
+ ReloadlyGiftcard.shared.allTransactions() { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testGetProductByISO() {
+ ReloadlyGiftcard.shared.getProductByISO(countryCode: "US") { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testRedeemInstructionById() {
+ ReloadlyGiftcard.shared.redeemInstruction(by: 1) { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testRedeemInstructions() {
+ ReloadlyGiftcard.shared.redeemInstruction() { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testOrderGiftcard() {
+ ReloadlyGiftcard.shared.orderGiftcard(with: 1, countryCode: "US", quantity: 1, unitPrice: 25.00, customIdentifier: "obucks10", senderName: "John Doe", recipientEmail: "anyone@email.com") { result in
+ XCTAssertNotNil(result)
+ }
+ }
+
+ func testModes() {
+ let orderGiftcard = OrderGiftcard(transactionId: 1, amount: 1.2, discount: 12.1, currencyCode: "ds", fee: 12.12, recipientEmail: "sd", customIdentifier: "sd", status: "fsff", product: Discount(percentage: 1.1, internationalPercentage: 1.2, localPercentage: 32.2, updatedAt: "sdfs", contentOperator: Operator(id: 23, operatorId: 23, name: "sf", countryCode: "dsf", data: false, bundle: false, status: false)), transactionCreatedTime: "sdas")
+ XCTAssertEqual(1, orderGiftcard.transactionId)
+ let redeemCode = RedeemCode(cardNumber: "4343", pinCode: "1234")
+ XCTAssertEqual("4343", redeemCode.cardNumber)
+ let products = Products(content: [ProductContent](), pageable: nil, last: nil, totalPages: nil, totalElements: nil, first: nil, sort: nil, numberOfElements: nil, size: nil, number: nil, empty: nil)
+ XCTAssertEqual(0, products.content?.count)
+ }
+
+}
diff --git a/ReloadlySDK.podspec b/ReloadlySDK.podspec
index 67d7ecb..bd8ac9e 100644
--- a/ReloadlySDK.podspec
+++ b/ReloadlySDK.podspec
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'ReloadlySDK'
- s.version = '1.0.3'
+ s.version = '1.0.4'
s.summary = 'The Reloadly SDK to easily work with Reloadly Services'
@@ -21,7 +21,7 @@ The Reloadly SDK for iOS enables iOS developers to easily work with Reloadly Ser
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '4taras4' => '4taras4@gmail.com' }
s.source = { :git => 'https://github.com/Reloadly/reloadly-sdk-ios.git', :tag => s.version.to_s }
- s.swift_version = ['4.2', '5.0']
+ s.swift_version = ['4.2', '5.3']
s.ios.deployment_target = '10.0'
s.source_files = 'ReloadlySDK/Classes/**/*'
@@ -36,4 +36,7 @@ The Reloadly SDK for iOS enables iOS developers to easily work with Reloadly Ser
co.source_files = "ReloadlySDK/Classes/ReloadlyAuthentication/**/*.swift"
end
+ s.subspec 'Giftcard' do |co|
+ co.source_files = "ReloadlySDK/Classes/ReloadlyGiftcard/**/*.swift"
+ end
end
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/CountryModel.swift b/ReloadlySDK/Classes/ReloadlyAirtime/Models/CountryModel.swift
deleted file mode 100644
index 89965aa..0000000
--- a/ReloadlySDK/Classes/ReloadlyAirtime/Models/CountryModel.swift
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// CountryModel.swift
-// ReloadlyAuthentication
-//
-// Created by Taras Markevych on 15.03.2021.
-//
-
-import Foundation
-
-public struct Country: Codable {
- public var isoName: String
- public var name: String
- public var currencyCode: String
- public var currencyName: String
- public var currencySymbol: String
- public var flag: String
- public var callingCodes: [String]
-
-}
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/ReloadlyAirtime.swift b/ReloadlySDK/Classes/ReloadlyAirtime/ReloadlyAirtime.swift
index d98ccd6..f631e5f 100644
--- a/ReloadlySDK/Classes/ReloadlyAirtime/ReloadlyAirtime.swift
+++ b/ReloadlySDK/Classes/ReloadlyAirtime/ReloadlyAirtime.swift
@@ -60,11 +60,11 @@ public class ReloadlyAirtime {
}
}
- public func getDiscountsByOperator(id: Int, completionHandler: @escaping (Result) -> Void) {
+ public func getDiscountsByOperator(id: Int, completionHandler: @escaping (Result) -> Void) {
NetworkManager.shared.dataTask(serviceURL: "/operators/\(id)/commissions", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
switch result {
case .success(let data):
- let discount: Result = self.processSuccess(data: data)
+ let discount: Result = self.processSuccess(data: data)
completionHandler(discount)
case .failure(let error):
completionHandler(.failure(error))
@@ -112,11 +112,11 @@ public class ReloadlyAirtime {
}
- public func getTransactionById(id: Int, completionHandler: @escaping (Result) -> Void) {
+ public func getTransactionById(id: Int, completionHandler: @escaping (Result) -> Void) {
NetworkManager.shared.dataTask(serviceURL: "/topups/reports/transactions/\(id)", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
switch result {
case .success(let data):
- let discount: Result = self.processSuccess(data: data)
+ let discount: Result = self.processSuccess(data: data)
completionHandler(discount)
case .failure(let error):
completionHandler(.failure(error))
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/BalanceModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/BalanceModel.swift
similarity index 100%
rename from ReloadlySDK/Classes/ReloadlyAirtime/Models/BalanceModel.swift
rename to ReloadlySDK/Classes/ReloadlyAuthentication/Models/BalanceModel.swift
diff --git a/ReloadlySDK/Classes/ReloadlyAuthentication/Models/CountryModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/CountryModel.swift
new file mode 100644
index 0000000..58272ca
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/CountryModel.swift
@@ -0,0 +1,19 @@
+//
+// CountryModel.swift
+// ReloadlyAuthentication
+//
+// Created by Taras Markevych on 15.03.2021.
+//
+
+import Foundation
+
+public struct Country: Codable {
+ public var isoName: String?
+ public var name: String?
+ public var currencyCode: String?
+ public var currencyName: String?
+ public var currencySymbol: String?
+ public var flag: String?
+ public var callingCodes: [String]?
+
+}
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/DiscountsModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/DiscountsModel.swift
similarity index 73%
rename from ReloadlySDK/Classes/ReloadlyAirtime/Models/DiscountsModel.swift
rename to ReloadlySDK/Classes/ReloadlyAuthentication/Models/DiscountsModel.swift
index 6583202..72c20c2 100644
--- a/ReloadlySDK/Classes/ReloadlyAirtime/Models/DiscountsModel.swift
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/DiscountsModel.swift
@@ -9,7 +9,7 @@ import Foundation
// MARK: - Discounts
public struct Discounts: Codable {
- public let content: [Content]
+ public let content: [Discount]
public let pageable: Pageable
public let totalElements: Int
public let totalPages: Int
@@ -21,7 +21,7 @@ public struct Discounts: Codable {
public let number: Int
public let empty: Bool
- public init(content: [Content], pageable: Pageable, totalElements: Int, totalPages: Int, last: Bool, sort: Sort, first: Bool, numberOfElements: Int, size: Int, number: Int, empty: Bool) {
+ public init(content: [Discount], pageable: Pageable, totalElements: Int, totalPages: Int, last: Bool, sort: Sort, first: Bool, numberOfElements: Int, size: Int, number: Int, empty: Bool) {
self.content = content
self.pageable = pageable
self.totalElements = totalElements
@@ -66,7 +66,7 @@ public struct Transactions: Codable {
}
// MARK: - Content
-public struct Content: Codable {
+public struct Discount: Codable {
public let percentage: Double?
public let internationalPercentage: Double?
public let localPercentage: Double?
@@ -103,34 +103,3 @@ public struct Operator: Codable {
}
}
-// MARK: - Pageable
-public struct Pageable: Codable {
- public let sort: Sort
- public let pageNumber: Int
- public let pageSize: Int
- public let offset: Int
- public let unpaged: Bool
- public let paged: Bool
-
- public init(sort: Sort, pageNumber: Int, pageSize: Int, offset: Int, unpaged: Bool, paged: Bool) {
- self.sort = sort
- self.pageNumber = pageNumber
- self.pageSize = pageSize
- self.offset = offset
- self.unpaged = unpaged
- self.paged = paged
- }
-}
-
-// MARK: - Sort
-public struct Sort: Codable {
- public let unsorted: Bool
- public let sorted: Bool
- public let empty: Bool
-
- public init(unsorted: Bool, sorted: Bool, empty: Bool) {
- self.unsorted = unsorted
- self.sorted = sorted
- self.empty = empty
- }
-}
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/OperatorModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/OperatorModel.swift
similarity index 100%
rename from ReloadlySDK/Classes/ReloadlyAirtime/Models/OperatorModel.swift
rename to ReloadlySDK/Classes/ReloadlyAuthentication/Models/OperatorModel.swift
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/PhoneModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/PhoneModel.swift
similarity index 100%
rename from ReloadlySDK/Classes/ReloadlyAirtime/Models/PhoneModel.swift
rename to ReloadlySDK/Classes/ReloadlyAuthentication/Models/PhoneModel.swift
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/PromotionModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/PromotionModel.swift
similarity index 100%
rename from ReloadlySDK/Classes/ReloadlyAirtime/Models/PromotionModel.swift
rename to ReloadlySDK/Classes/ReloadlyAuthentication/Models/PromotionModel.swift
diff --git a/ReloadlySDK/Classes/ReloadlyAuthentication/Models/SortModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/SortModel.swift
new file mode 100644
index 0000000..bdee620
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/SortModel.swift
@@ -0,0 +1,38 @@
+//
+// SortModel.swift
+// ReloadlySDK
+//
+// Created by Tarik on 13.01.2022.
+//
+
+// MARK: - Pageable
+public struct Pageable: Codable {
+ public let sort: Sort
+ public let pageNumber: Int
+ public let pageSize: Int
+ public let offset: Int
+ public let unpaged: Bool
+ public let paged: Bool
+
+ public init(sort: Sort, pageNumber: Int, pageSize: Int, offset: Int, unpaged: Bool, paged: Bool) {
+ self.sort = sort
+ self.pageNumber = pageNumber
+ self.pageSize = pageSize
+ self.offset = offset
+ self.unpaged = unpaged
+ self.paged = paged
+ }
+}
+
+// MARK: - Sort
+public struct Sort: Codable {
+ public let unsorted: Bool
+ public let sorted: Bool
+ public let empty: Bool
+
+ public init(unsorted: Bool, sorted: Bool, empty: Bool) {
+ self.unsorted = unsorted
+ self.sorted = sorted
+ self.empty = empty
+ }
+}
diff --git a/ReloadlySDK/Classes/ReloadlyAirtime/Models/TopupsModel.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Models/TopupsModel.swift
similarity index 100%
rename from ReloadlySDK/Classes/ReloadlyAirtime/Models/TopupsModel.swift
rename to ReloadlySDK/Classes/ReloadlyAuthentication/Models/TopupsModel.swift
diff --git a/ReloadlySDK/Classes/ReloadlyAuthentication/Network/NetworkManager.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Network/NetworkManager.swift
index e3c23cb..6d06415 100644
--- a/ReloadlySDK/Classes/ReloadlyAuthentication/Network/NetworkManager.swift
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/Network/NetworkManager.swift
@@ -30,7 +30,7 @@ class NetworkManager {
private func requestAuth(serviceURL: String, httpMethod: HttpMethod, parameters: [String:String]?, proxyConfigurator: ProxyConfigurator? = nil, completion: @escaping (Result) -> Void) -> Void {
- var request = URLRequest(url: URL(string: "https://auth.reloadly.com\(serviceURL)")!)
+ var request = URLRequest(url: URL(string: "\(ReloadlyAuthentication.shared.service.backendEnvironment.authURL)\(serviceURL)")!)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = httpMethod.rawValue
diff --git a/ReloadlySDK/Classes/ReloadlyAuthentication/ReloadlyAuthentication.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/ReloadlyAuthentication.swift
index 50b2c85..74e9431 100644
--- a/ReloadlySDK/Classes/ReloadlyAuthentication/ReloadlyAuthentication.swift
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/ReloadlyAuthentication.swift
@@ -18,8 +18,8 @@ public class ReloadlyAuthentication {
public static let shared = ReloadlyAuthentication()
let storageKey = "OAuth2Token"
- /// Service's backend environment. Default value is `.production`. Make sure to use `.production` in you release (App Store)
- public private(set) var service: AuthenticationServiceProtocol = AuthenticationService(backendEnvironment: .sandbox)
+ /// Service's backend environment. Default value is `.airtimeSandbox`. Make sure to use `.airtimeProduction` in you release (App Store)
+ public private(set) var service: AuthenticationServiceProtocol = AuthenticationService(backendEnvironment: .airtimeSandbox)
let storage = Keychain()
private var clientId: String?
private var clientSecret: String?
@@ -57,7 +57,7 @@ public class ReloadlyAuthentication {
*/
public func configure(with clientId: String? = nil, clientSecret: String? = nil, service: AuthenticationServiceProtocol? = nil, logLevel: Level = .info, proxyConfiguration: ProxyConfigurator? = nil, useTelemetry: Bool = true) {
let dictionary = Bundle.main.infoDictionary
- self.service = service ?? AuthenticationService(backendEnvironment: (dictionary?["ReloadlySDKEnvironment"] as? String) ?? "sandbox")
+ self.service = service ?? AuthenticationService(backendEnvironment: (dictionary?["ReloadlySDKEnvironment"] as? String) ?? "airtimeSandbox")
self.clientId = clientId ?? (dictionary?["ReloadlySDKClientId"] as? String) ?? ""
self.clientSecret = clientSecret ?? (dictionary?["ReloadlySDKSecretId"] as? String) ?? ""
self.logger.minLevel = logLevel
diff --git a/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationBackendEnvironment.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationBackendEnvironment.swift
index cb7cb17..d02b647 100644
--- a/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationBackendEnvironment.swift
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationBackendEnvironment.swift
@@ -9,14 +9,26 @@ import Foundation
import Foundation
public enum AuthenticationBackendEnvironment: String {
- case production
- case sandbox
+ case airtimeProduction
+ case airtimeSandbox
+ case giftcardProduction
+ case giftcardSandbox
var baseURL: String {
let environment = ReloadlyAuthentication.shared.service.backendEnvironment
switch environment {
- case .production: return "https://topups.reloadly.com"
- case .sandbox: return "https://topups-sandbox.reloadly.com"
+ case .airtimeProduction: return "https://topups.reloadly.com"
+ case .airtimeSandbox: return "https://topups-sandbox.reloadly.com"
+ case .giftcardProduction: return "https://giftcards.reloadly.com"
+ case .giftcardSandbox: return "https://giftcards-sandbox.reloadly.com"
+ }
+ }
+
+ var authURL: String {
+ let environment = ReloadlyAuthentication.shared.service.backendEnvironment
+ switch environment {
+ case .airtimeSandbox, .airtimeProduction: return "https://auth.reloadly.com"
+ case .giftcardSandbox, .giftcardProduction: return "https://auth.reloadly.com"
}
}
}
diff --git a/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationService.swift b/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationService.swift
index 411e02d..bb5f3c1 100644
--- a/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationService.swift
+++ b/ReloadlySDK/Classes/ReloadlyAuthentication/Utilities/AuthenticationService.swift
@@ -26,7 +26,7 @@ public final class AuthenticationService: AuthenticationServiceProtocol {
}
public init(backendEnvironment: String) {
- self.backendEnvironment = AuthenticationBackendEnvironment(rawValue: backendEnvironment) ?? .sandbox
+ self.backendEnvironment = AuthenticationBackendEnvironment(rawValue: backendEnvironment) ?? .airtimeSandbox
}
private func notifyAboutUpdate() {
diff --git a/ReloadlySDK/Classes/ReloadlyGiftcard/Models/OrderGiftcardModel.swift b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/OrderGiftcardModel.swift
new file mode 100644
index 0000000..279eefc
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/OrderGiftcardModel.swift
@@ -0,0 +1,34 @@
+//
+// OrderGiftcard.swift
+// ReloadlySDK
+//
+// Created by Tarik on 22.11.2021.
+//
+
+import Foundation
+
+public struct OrderGiftcard: Codable {
+ public let transactionId: Int?
+ public let amount: Double?
+ public let discount: Double?
+ public let currencyCode: String?
+ public let fee: Double?
+ public let recipientEmail: String?
+ public let customIdentifier: String?
+ public let status: String?
+ public let product: Discount?
+ public let transactionCreatedTime: String?
+
+ public init(transactionId: Int?, amount: Double?, discount: Double?, currencyCode: String?, fee: Double?, recipientEmail: String?, customIdentifier: String?, status: String?, product: Discount?, transactionCreatedTime: String?) {
+ self.transactionId = transactionId
+ self.amount = amount
+ self.discount = discount
+ self.currencyCode = currencyCode
+ self.fee = fee
+ self.recipientEmail = recipientEmail
+ self.customIdentifier = customIdentifier
+ self.status = status
+ self.product = product
+ self.transactionCreatedTime = transactionCreatedTime
+ }
+}
diff --git a/ReloadlySDK/Classes/ReloadlyGiftcard/Models/ProductsModel.swift b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/ProductsModel.swift
new file mode 100644
index 0000000..a365796
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/ProductsModel.swift
@@ -0,0 +1,98 @@
+import Foundation
+
+// MARK: - Products
+public struct Products: Codable {
+ public let content: [ProductContent]?
+ public let pageable: Pageable?
+ public let last: Bool?
+ public let totalPages: Int?
+ public let totalElements: Int?
+ public let first: Bool?
+ public let sort: Sort?
+ public let numberOfElements: Int?
+ public let size: Int?
+ public let number: Int?
+ public let empty: Bool?
+
+ public init(content: [ProductContent]?, pageable: Pageable?, last: Bool?, totalPages: Int?, totalElements: Int?, first: Bool?, sort: Sort?, numberOfElements: Int?, size: Int?, number: Int?, empty: Bool?) {
+ self.content = content
+ self.pageable = pageable
+ self.last = last
+ self.totalPages = totalPages
+ self.totalElements = totalElements
+ self.first = first
+ self.sort = sort
+ self.numberOfElements = numberOfElements
+ self.size = size
+ self.number = number
+ self.empty = empty
+ }
+}
+
+// MARK: - Content
+public struct ProductContent: Codable {
+ public let productId: Int?
+ public let productName: String?
+ public let global: Bool?
+ public let senderFee: Double?
+ public let discountPercentage: Double?
+ public let denominationType: String?
+ public let recipientCurrencyCode: String?
+ public let minRecipientDenomination: String?
+ public let maxRecipientDenomination: String?
+ public let senderCurrencyCode: String?
+ public let minSenderDenomination: String?
+ public let maxSenderDenomination: String?
+ public let fixedRecipientDenominations: [Double]?
+ public let fixedSenderDenominations: [Double]?
+ public let fixedRecipientToSenderDenominationsMap: [String: Double]?
+ public let logoUrls: [String]?
+ public let brand: Brand?
+ public let country: Country?
+ public let redeemInstruction: RedeemInstruction?
+
+ public init(productId: Int?, productName: String? = nil, global: Bool? = nil, senderFee: Double? = nil, discountPercentage: Double? = nil, denominationType: String? = nil, recipientCurrencyCode: String? = nil, minRecipientDenomination: String? = nil, maxRecipientDenomination: String? = nil, senderCurrencyCode: String? = nil, minSenderDenomination: String? = nil, maxSenderDenomination: String? = nil, fixedRecipientDenominations: [Double]? = nil, fixedSenderDenominations: [Double]? = nil, fixedRecipientToSenderDenominationsMap: [String: Double]? = nil, logoUrls: [String]? = nil, brand: Brand? = nil, country: Country? = nil, redeemInstruction: RedeemInstruction? = nil) {
+ self.productId = productId
+ self.productName = productName
+ self.global = global
+ self.senderFee = senderFee
+ self.discountPercentage = discountPercentage
+ self.denominationType = denominationType
+ self.recipientCurrencyCode = recipientCurrencyCode
+ self.minRecipientDenomination = minRecipientDenomination
+ self.maxRecipientDenomination = maxRecipientDenomination
+ self.senderCurrencyCode = senderCurrencyCode
+ self.minSenderDenomination = minSenderDenomination
+ self.maxSenderDenomination = maxSenderDenomination
+ self.fixedRecipientDenominations = fixedRecipientDenominations
+ self.fixedSenderDenominations = fixedSenderDenominations
+ self.fixedRecipientToSenderDenominationsMap = fixedRecipientToSenderDenominationsMap
+ self.logoUrls = logoUrls
+ self.brand = brand
+ self.country = country
+ self.redeemInstruction = redeemInstruction
+ }
+}
+
+// MARK: - Brand
+public struct Brand: Codable {
+ public let brandId: Int?
+ public let brandName: String?
+
+ public init(brandId: Int?, brandName: String?) {
+ self.brandId = brandId
+ self.brandName = brandName
+ }
+}
+
+
+// MARK: - RedeemInstruction
+public struct RedeemInstruction: Codable {
+ public let concise: String?
+ public let verbose: String?
+
+ public init(concise: String?, verbose: String?) {
+ self.concise = concise
+ self.verbose = verbose
+ }
+}
diff --git a/ReloadlySDK/Classes/ReloadlyGiftcard/Models/RecipientPhoneDetailsModel.swift b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/RecipientPhoneDetailsModel.swift
new file mode 100644
index 0000000..baa8be4
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/RecipientPhoneDetailsModel.swift
@@ -0,0 +1,4 @@
+public struct RecipientPhoneDetailsModel: Codable {
+ var countryCode:String?
+ var phoneNumber: String?
+}
diff --git a/ReloadlySDK/Classes/ReloadlyGiftcard/Models/RedeemCodeModel.swift b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/RedeemCodeModel.swift
new file mode 100644
index 0000000..84c2122
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyGiftcard/Models/RedeemCodeModel.swift
@@ -0,0 +1,18 @@
+//
+// RedeemCodeModel.swift
+// ReloadlySDK
+//
+// Created by Tarik on 22.11.2021.
+//
+
+import Foundation
+
+public struct RedeemCode: Codable {
+ public let cardNumber: String?
+ public let pinCode: String?
+
+ public init(cardNumber: String?, pinCode: String?) {
+ self.cardNumber = cardNumber
+ self.pinCode = pinCode
+ }
+}
diff --git a/ReloadlySDK/Classes/ReloadlyGiftcard/ReloadlyGiftcard.swift b/ReloadlySDK/Classes/ReloadlyGiftcard/ReloadlyGiftcard.swift
new file mode 100644
index 0000000..9262b6f
--- /dev/null
+++ b/ReloadlySDK/Classes/ReloadlyGiftcard/ReloadlyGiftcard.swift
@@ -0,0 +1,197 @@
+//
+// ReloadlyGiftcard.swift
+// ReloadlySDK
+//
+// Created by Tarik on 21.11.2021.
+//
+
+import Foundation
+
+public class ReloadlyGiftcard {
+
+ public static let shared = ReloadlyGiftcard()
+
+ public func getAllProducts(includeRange: Bool = false, includeFixed: Bool = false, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/products?includeRange=\(includeRange)&includeFixed=\(includeFixed)", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func getProduct(by id: Int, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/products/\(id)", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func getProductByISO(countryCode: String, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/countries/\(countryCode)/products", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func redeemInstruction(completionHandler: @escaping (Result<[Brand], Error>) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/redeem-instructions", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result<[Brand], Error> = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func redeemInstruction(by id: Int, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/brands/\(id)/redeem-instructions", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func discounts(page: Int = 1, size: Int = 50, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/discounts?page=\(page)&size=\(size)", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func discounts(by productId: Int, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/products/\(productId)/discounts", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+ public func allTransactions(completionHandler: @escaping (Result) -> Void) {
+ let url = "/reports/transactions"
+ NetworkManager.shared.dataTask(serviceURL: url, httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func transaction(by id: Int, completionHandler: @escaping (Result) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/reports/transactions/\(id)", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+
+ public func orderGiftcard(with productId: Int,
+ countryCode: String,
+ quantity: Int,
+ unitPrice: Double,
+ customIdentifier: String,
+ senderName: String,
+ recipientEmail: String? = nil,
+ recipientPhoneDetails: RecipientPhoneDetailsModel? = nil,
+ completionHandler: @escaping (Result) -> Void) {
+ var parameters: [String: Any] = [
+ "productId": productId,
+ "countryCode": countryCode,
+ "quantity": quantity,
+ "unitPrice": unitPrice,
+ "customIdentifier": customIdentifier,
+ "senderName": senderName]
+ if let recipientEmail = recipientEmail {
+ parameters.updateValue(recipientEmail, forKey: "recipientEmail")
+ }
+
+ if let recipientPhoneDetails = recipientPhoneDetails,
+ let countryCode = recipientPhoneDetails.countryCode,
+ let phone = recipientPhoneDetails.phoneNumber {
+ let value = ["countryCode": countryCode,
+ "phoneNumber": phone
+ ]
+ parameters.updateValue(value, forKey: "recipientPhoneDetails")
+ }
+
+ if recipientEmail == nil && recipientPhoneDetails == nil {
+ completionHandler(.failure(ServiceError.unableToProcesRequest(message: "recipientPhoneDetails or recipientEmail should be filled")))
+ return
+ }
+
+ NetworkManager.shared.dataTask(serviceURL: "/orders", httpMethod: .post, parameters: parameters, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+
+ public func redeemCode(by transactionId: Int, completionHandler: @escaping (Result<[RedeemCode], Error>) -> Void) {
+ NetworkManager.shared.dataTask(serviceURL: "/orders/transactions/\(transactionId)/cards", httpMethod: .get, parameters: nil, proxyConfigurator: ReloadlyAuthentication.shared.proxyConfiguration) { result in
+ switch result {
+ case .success(let data):
+ let result: Result<[RedeemCode], Error> = self.processSuccess(data: data)
+ completionHandler(result)
+ case .failure(let error):
+ completionHandler(.failure(error))
+ }
+ }
+ }
+}
+
+extension ReloadlyGiftcard {
+ func processSuccess(data: Data) -> Result {
+ do {
+ let model = try JSONDecoder().decode(T.self, from: data)
+ ReloadlyAuthentication.shared.logger.debug("Receive model: \(model)")
+ return .success(model)
+ } catch let error {
+ if let serverError: ErrorModel = try? JSONDecoder().decode(ErrorModel.self, from: data) {
+ ReloadlyAuthentication.shared.logger.error("\(serverError)")
+ return.failure(ServiceError.unableToProcesRequest(message: serverError.message))
+ } else {
+ ReloadlyAuthentication.shared.logger.error("\(error)")
+ return.failure(error)
+ }
+ }
+ }
+}