NAV Navbar
Swift Objective-C

Sibche Documentation

Welcome to Sibche Documentation.
If you are a Unity developer, you can find related documents in the menu on the right, selecting “Install Unity SDK” option, otherwise you can find the “Install SDK” option to be helpful for you.
At whatever point in the document, you can use the upper-left menu to select your programming language (in case you are a Unity developer, you need to use select C#)
Best of luck!

Installing SDK

SDK requirements:

  1. Uploading the app in Sibche Developer Dashboard
  2. Receiving app key from Dashboard
  3. Latest version of Xcode

Installing SDK

Installation using Cocoapods:

You only need to input the following code into your podfile:

pod 'SibcheStoreKit', '~> 4.1'

Then install the added pad

pod repo update
pod install

Manual Installation:

You can download the Sibche SDK from here and add it to your project. For that you need to extract the downloaded file and copy SibcheStoreKit.framework into your project folder and add it to your project as such:

Then you need to select a plugin file and click on “add”. After that, as displayed below, delete SibcheStoreKit.framework from Linked Frameworks and Libraries in the “General” tab:

Then click on the + button in Embedded Binaries tab and select SibcheStoreKit.framework and click “add” as displayed below:

Default settings:

Adding your apps exclusive Scheme

In order to add exclusive Scheme, you need to open the settings in Xcode and go to “info” tab as such:

Then, like so, add your app’s URL in the field:

Chose a name and put it in the testapp field, this name will be the name of your Scheme. For example, the Scheme name of Telegram is set to tg and for Instagram, it is set to Instagram. You can view a list of popular apps here.

How to add the developer kit to AppDelegate:

First, add the developer kit activation code into the following function:

#import "AppDelegate.h"
#import <SibcheStoreKit/SibcheStoreKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [SibcheStoreKit initWithApiKey:YOUR_API_KEY withScheme:YOUR_SCHEME];
    return YES;
}
import SibcheStoreKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    SibcheStoreKit.initWithApiKey(YOUR_API_KEY, withScheme: YOUR_SCHEME)
    return true
}


It is noteworthy that you should insert the program key obtained from the Sibche developer panel in the place of YOUR_API_KEY. Also, the word scheme, which was added in the previous stage, must be placed instead of YOUR_SCHEME.



Then, give the developer kit the permission to open urls:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    [SibcheStoreKit openUrl:url options:options];
    return YES;
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    SibcheStoreKit.open(url, options: options)
    return true
}

Available classes of use for the developer kit:

In order to buy, activate and use Sibche packages, the following classes have been created. Some explanations regarding each of them will be presented in the following:

SibchePackage

There are three types of package available:

All of these packages fall under the umbrella package, SibchePackage and include the following functions:

- (NSString*)packageId;
- (NSString*)type;
- (NSString*)code;
- (NSString*)name;
- (NSString*)packageDescription;
- (NSNumber*)price;
- (NSNumber*)totalPrice;
- (NSNumber*)discount;
var packageId: String
var type: String
var code: String
var name: String
var packageDescription: String
var price: NSNumber
var totalPrice: NSNumber
var discount: NSNumber




also, the SibcheSubscriptionPackage includes the following additional functions:

- (NSNumber*)duration;
- (NSString*)group;
var duration: String
var group: String

SibchePurchasePackage

This package includes the user’s purchases corresponding with your packages. This class includes the following functions:

- (NSString*)purchasePackageId;
- (NSString*)type;
- (NSString*)code;
- (NSDate*)expireAt;
- (NSDate*)createdAt;
- (SibchePackage*)package;
var purchasePackageId: String
var type: String
var code: String
var expireAt: NSDate
var createdAt: NSDate
var package: SibchePackage




SibcheError

You will be provided with this class should an error with the following characteristics occur: - ErrorCode: the error code number can be observed in the following table. - Message: the error message which will be received from the server. - StatusCode: the http error code which the server provides in response to our request.

ErrorCode number Reason
1000 Unknown reason
1001 This package has be already purchased
1002 User has quit the process
1003 Login error
1004 Program has not initiated properly
@property NSNumber* errorCode;
@property NSString* message;
@property NSNumber* statusCode;
var NSNumber: errorCode
var message: String
var NSNumber: statusCode



How to get the list of available packages:

After tuning the options for the program, you can view the available packages. You must simply use the following code in order to receive the function of interest:

[SibcheStoreKit fetchInAppPurchasePackages:^(BOOL isSuccessful, SibcheError* error, NSArray *packagesArray) {
    // Your block code for handling of packages list
}];
SibcheStoreKit.fetch { (isSuccessful, error, packagesArray) in
    // Your block code for handling of packages list
}


If successful, the developer kit will provide you with the available packages in the form of a parameter. This parameter is an array of the packages which are available for purchase. These packages are of the SibchePackage kind.

In case the request is not successful, a parameter called error, which is of the SibcheError kind, will be sent.

How to get package information:

If you have the bundle code or ID of the package, you can obtain its information. The following is how to use this API:

// Both package bundle code & package id is acceptable

[SibcheStoreKit fetchInAppPurchasePackage:@"com.example.testapp" withPackagesCallback:^(BOOL isSuccessful, SibcheError* error, SibchePackage *package) {
   // Your block code for handling of packages list
}];
// Both package bundle code & package id is acceptable

SibcheStoreKit.fetch(inAppPurchasePackage: "com.example.testapp") { (isSuccessful, error, package) in
    // Your block code for handling of packages list
}

The initially presented parameter is the very callback that we sent which, after getting checked, was recalled. If successful, the package of interest will be sent to you in the object form of SibchePackage.

How to purchase a package:

After obtaining the package list, you can use the following code in order to set a purchase request through the developer kit. Next, the kit will, if necessary, log the client in and check up on the payment procedure. Then, it will tell you if the purchase has been successful or not and will provide you with a SibchePurchasePackage.

// Both package bundle code & package id is acceptable

[SibcheStoreKit purchasePackage:@"com.example.testapp" withCallback:^(BOOL isSuccessful, SibcheError* error, SibchePurchasePackage* purchasePackage) {
    // Your block code for handling of purchase callback
}];
// Both package bundle code & package id is acceptable

SibcheStoreKit.purchasePackage("com.example.testapp") { (isSuccessful, error, purchasePackage) in
  // Your block code for handling of purchase callback
}


How to obtain the list of previous purchases:

You can use the following code to obtain your active (purchased) packages. Just simply call in the developer kit function as in the following code.

[SibcheStoreKit fetchActiveInAppPurchasePackages:^(BOOL isSuccessful, SibcheError* error, NSArray *purchasePackagesArray) {
  // Your block code for handling of packages list
}];
SibcheStoreKit.fetchActive { (isSuccessful, error, purchasePackagesArray) in
  // Your block code for handling of packages list
}

In response, the kit will provide you with information as to whether the request was successful or not, as well as an array of active purchased packages. Take note that this array is of the SibchePurchasePackage kind

Active packages are those which have not yet run out of time or have not been used up completely. The Sibche definition for active packages for each of the package types is as follows:

Using up packages on the part of the client:

[SibcheStoreKit consumePurchasePackage:purchasePackageData.purchasePackageId withCallback:^(BOOL isSuccessful, SibcheError* error) {
   // Your block code for handling of package consume
}];
SibcheStoreKit.consumePurchasePackage(purchasePackageData.purchasePackageId) { (isSuccessful, error) in
  // Your block code for handling of package consume
}

In response, after the request status has been checked, the developer kit will recall the requested callback. If it is successful, it means that the package has been used up successfully, but if it is unsuccessful, it means that an error has occurred in the usage procedure.

Using up packages on the part of the server:

To do this, you must have purchasePackageId which is part of the SibchePurchasePackage class. Then, you must make a link similar to the following and receive the verification data from the server (addresses are case sensitive!):

https://api.sibche.com/sdk/userInAppPurchasePackages/{purchasePackageId}/verifyConsume

Also, the HTTP header must be set onto the App-Key for this operation. This key is available for any specific program through the developer panel. This key is called the server key and has 30 characters.

A sample of code which can be recalled for curl can be as follows:

curl --header "App-Key: YOUR_SERVER_KEY" -X POST \
'https://api.sibche.com/sdk/userInAppPurchasePackages/1/verifyConsume'



In response, the server will provide one of these HTTP Response Codes: - HTTP Status Code 404 (Not Found): this occurs either when you misspell the address link or package, or if the package has already been used. In this case the server will respond with something like this code:

{
  "message" : "your package is already is used or not found",
  "status_code" : 404
}



{
  "message" : "app-key is not valid",
  "status_code" : 401
}



Client login request to the Sibche developer kit:

By using this code, you can send a login request to the Sibche library. All you need to do is, as it is done below, recall the function relating to the developer kit.

[SibcheStoreKit loginUser:^(BOOL isLoginSuccessful, SibcheError* error, NSString *userName, NSString *userId) {
    // Your code for handling of login result
}];
SibcheStoreKit.loginUser { (isLogginSuccessful, error, userName, userId) in
    // Your code for handling of login result
}


In response, the developer kit will provide information regarding the successfulness of the login and the errors it faced in the process.

How to logout of the Sibche developer kit:

By the use of this code, you can logout the client who is already logged in to the developer kit and delete their session information. This function will provide a response to you in the form of a callback.

[SibcheStoreKit logoutUser:^{
    // Your code for handling of logout result
}];
SibcheStoreKit.logoutUser {
    // Your code for handling of logout result
}

How to obtain information on current clients:

When you need to get the client’s phone number and userID you can use the following function:

[SibcheStoreKit getCurrentUserData:^(BOOL isSuccessful, SibcheError *error, LoginStatusType loginStatus, NSString *userCellphoneNumber, NSString *userId) {
    // Your code for handling of get current user data result
}];
SibcheStoreKit.getCurrentUserData { (isSuccessful, error, loginStatus, userCellphoneNumber, userId) in
    // Your code for handling of get current user data result
}



In response, the developer kit will tell you if the process was successful or not and also recalls the error that may have occurred. In most cases the process will go smoothly, but in some rare cases, the following reasons could be why the process wasn’t successful:

In addition, a third parameter exists which tells you whether the client is logged in or not. if the client is logged in, the response type will be of this kind loginStatusTypeIsLoggedIn. If they are not logged in, the response type will be of the loginStatusTypeIsLoggedOut kind. If the process is not successful and we are not sure whether the client is logged in or not, we will get a response which is of the loginStatusTypeHaveTokenButFailedToCheck kind. The next parameters in the received response will include the client’s phone number and ID.

Installing Unity SDK

Unity developer kit installment requirements:

  1. Uploading the app in Sibche Developer Dashboard
  2. Receive the program key from the developer panel
  3. Latest version of Xcode
  4. Unity v2019.1 and above

How to install the unity developer kit:

You can download the Sibche developer kit specific to unity from this link and add it to your project.

Basic settings (unity):

The required settings for a project are automatically added in the project under the editor section. SibcheBuildPostProcessor.cs is the file name.

This file includes two setting sections: one is meant for the addition of the specific scheme or url of your game and the other is meant for the addition of the project file to the project in a dynamic fashion. Both cases will be explained in detail.

Adding your program’s specific scheme:

If your program has a specific scheme or url you must turn this setting off from the SibcheBuildPostProcessor.cs section. Just like the below mentioned code, you can set your specific url onto the project. csharp AddCustomUrlScheme(path, "testapp", "test");

Instead of test, set your preferred name and instead of testapp, place your preferred scheme. For instance, the schemes which are set for Telegram and Instagram are tg and Instagram, respectively. A full list of popular schemes can be found here.

I highly recommend that you use a scheme that is specific to you and is preferably long. Take caution that if your scheme interferes with another program you may encounter issues regarding payment.

How to add a .framework file to the dynamic library (embedded framework):

This section has done all that is needed to be done in regards to making the project dynamic and all that you need to do is leave it as it is:

AddSibcheFrameworkAsEmbed(path);

Adding initial init Sibche library:

At the beginning of the main class (start function), you must recall the init Sibche library function in order to use it in the following stages.

using SibcheStoreKit;

public class GameController : MonoBehaviour
{
    // ...

    private void Start()
    {
        //Other initiation tasks

        // Sibche StoreKit initiation
        Sibche.Initialize(YOUR_API_KEY, YOUR_SCHEME);
    }

    // ...
}

Instead of YOUR_API_KEY, you must enter the api key which you received from the Sibche developer panel. Also, instead of YOUR_SCHEME, you must enter the scheme which was defined in the previous stages.

Classes of use in the developer kit (unity):

In order to buy, activate and use the Sibche packages, the following classes have been created. Some explanations regarding each class are presented as follows:

SibchePackage

There are three types of package available:

All of these packages fall under the umbrella package, SibchePackage and include the following characteristics:

public string packageId;
public string type;
public string code;
public string name;
public string packageDescription;
public int price;
public int totalPrice;
public int discount;

also, the SibcheSubscriptionPackage includes the following additional characteristics:

public int duration;
public string group;

SibchePurchasePackage

This package includes the user’s purchases corresponding with your packages. This class includes the following characteristics:

public string purchasePackageId;
public string type;
public string code;
public DateTime expireAt;
public DateTime createdAt;
public SibchePackage package;

SibcheError

You will be provided with this class should an error with the following characteristics occur:

public string message;
public int errorCode;
public int statusCode;
ErrorCode number Reason
1000 Unknown reason
1001 This package has be already purchased
1002 User has quit the process
1003 Login error
1004 Program has not initiated properly

How to get the list of available packages (unity):

After tuning the options for the program, you can view the available packages. You must simply use the following code in order to receive the function of interest:

Sibche.FetchPackages((bool isSuccessful, SibcheError error, List<SibchePackage> packages) =>
{
    if (isSuccessful)
    {
        // Success block
    } else
    {
        // failure block
        Debug.Log(error.message);
    }
});

If successful, the developer kit will provide you with the available packages in the form of a parameter. This parameter is an array of the packages which are available for purchase. These packages are of the SibchePackage kind.

In case the request is not successful, a parameter called error, which is of the SibcheError kind, will be sent. If such is not the case, null will be sent.

How to get package information (unity):

If you have the bundle code or ID of the package, you can obtain its information. The following is how to use this API:

// Both package bundle code & package id is acceptable
Sibche.FetchPackage(packageId, (bool isSuccessful1, SibcheError error, SibchePackage package) =>
{
    if (isSuccessful)
    {
        // Success block
    } else
    {
        // failure block
        Debug.Log(error.message);
    }
});

The initially presented parameter is the very callback that we sent which, after getting checked, was recalled. If successful, the package of interest will be sent to you in the object form of SibchePackage.

How to purchase a package (unity):

After obtaining the package list, you can use the following code in order to set a purchase request through the developer kit. Next, the kit will, if necessary, log the client in and check up on the payment procedure. Then, it will tell you if the purchase has been successful or not and will provide you with a SibchePurchasePackage.

Sibche.Purchase(packageCode, (bool isSuccessful, SibcheError error, SibchePurchasePackage purchasedPackage) =>
{
    if (isSuccessful)
    {
        // Success block
    } else
    {
        // failure block
        Debug.Log(error.message);
    }
});

How to obtain the list of previous purchases (unity):

You can use the following code to obtain your active (purchased) packages. Just simply call in the developer kit function as in the following code.

Sibche.FetchActivePackages((bool isSuccessful, SibcheError error, List<SibchePurchasePackage> purchasedPackages) =>
{
    if (isSuccessful)
    {
        // Success block
    } else
    {
        // failure block
        Debug.Log(error.message);
    }
});

In response, the kit will provide you with information as to whether the request was successful or not, as well as an array of active purchased packages. Take note that this array is of the SibchePurchasePackage kind.

Active packages are those which have not yet run out of time or have not been used up completely. The Sibche definition for active packages for each of the package types is as follows:

Using up packages on the part of the client (unity):

Note: this method should be used in order for the client to use the package in programs or games. However, if the server is to use or validate them, please refer to the next section. In order to use the consumable packages, you must recall the associated function from the developer kit, similar to the following code:

Sibche.Consume(purchasedPackage.purchasePackageId, (bool isSuccessful, SibcheError error) =>
{
    if (isSuccessful)
    {
        // Success block
    } else
    {
        // failure block
        Debug.Log(error.message);
    }
});

In response, after the request status has been checked, the developer kit will recall the requested callback. If it is successful, it means that the package has been used up successfully, but if it is unsuccessful, it means that an error has occurred in the usage procedure.

Using up packages on the part of the server (unity):

To do this, you must have purchasePackageId which is part of the SibchePurchasePackage class. Then, you must make a link similar to the following and receive the verification data from the server (addresses are case sensitive!):

https://api.sibche.com/sdk/userInAppPurchasePackages/{purchasePackageId}/verifyConsume

Also, the HTTP header must be set onto the App-Key for this operation. This key is available for any specific program through the developer panel. This key is called the server key and has 30 characters.

A sample of code which can be recalled for curl can be as follows:

curl --header "App-Key: YOUR_SERVER_KEY" -X POST \
'https://api.sibche.com/sdk/userInAppPurchasePackages/1/verifyConsume'

In response, the server will provide one of these HTTP Response Codes:

{
  "message" : "your package is already is used or not found",
  "status_code" : 404
}
{
  "message" : "app-key is not valid",
  "status_code" : 401
}

Client login request to the Sibche developer kit (unity):

Note: I recommend that you don’t use this section manually because if the client has not logged in during the payment process, the Sibche library will automatically attempt to do so.

By using this code, you can send a login request to the Sibche library. All you need to do is, as it is done below, recall the function relating to the developer kit.

Sibche.Login((bool isLoginSuccessful, SibcheError error, string userName, string userId) =>
{
    // Login handle block
});

In response, the developer kit will provide information regarding the successfulness of the login and the errors it faced in the process.

How to logout of the Sibche developer kit (unity):

Note: I highly recommend that you only use this function when the client has requested the retrieval of their purchase and has their retrieval request in hand.

Sibche.Logout(() =>
{
    // Logout handle block
});

By the use of this code, you can logout the client who is already logged in to the developer kit and delete their session information. This function will provide a response to you in the form of a callback.

How to obtain information on current clients (unity):

When you need to get the client’s phone number and userID you can use the following function:

Sibche.GetCurrentUserData((bool isSuccessful, SibcheError error, LoginStatusType loginStatus, string userCellphoneNumber, string userId) =>
{
    // GetCurrentUserData handle block
});

In response, the developer kit will tell you if the process was successful or not and also recalls the error that may have occurred. In most cases the process will go smoothly, but in some rare cases, the following reasons could be why the process wasn’t successful:

In addition, a third parameter exists which tells you whether the client is logged in or not. if the client is logged in, the response type will be of this kind loginStatusTypeIsLoggedIn. If they are not logged in, the response type will be of the loginStatusTypeIsLoggedOut kind. If the process is not successful and we are not sure whether the client is logged in or not, we will get a response which is of the loginStatusTypeHaveTokenButFailedToCheck kind. The next parameters in the received response will include the client’s phone number and ID.

How to install the Corona developer kit

Corona plugin requirements

  1. Uploading the app in Sibche Developer Dashboard
  2. Receiving app key from Dashboard
  3. Latest version of Xcode
  4. Latest version of Corona (Above 2020.3577)

Installing the Corona plugin

Adding the sibche plugin to the corona project

    plugins =
    {
        ["plugin.SibcheStoreKit"] =
        {
            publisherId = "com.sibche",
            supportedPlatforms = { 
                iphone = { url="https://raw.githubusercontent.com/sibche/SibcheStoreKit-Corona/master/iphone.tgz" },
                ["iphone-sim"] = { url="https://raw.githubusercontent.com/sibche/SibcheStoreKit-Corona/master/iphone-sim.tgz" },
                android = false,
                macos = false,
                win32 = false
            },
        },
    },

In order to install Sibche Plugin, you must copy the following code in build.settings file and then click on the (Download Plugins) from Xcode menu.

Default settings (corona)

Adding your app’s exclusive Schemeا

In order to add exclusive Scheme, you need to open the settings in Xcode and go to info tab as such:

Then, like so, add your app’s URL in the field:

Chose a name and put it in the testapp field, this name will be the name of your Scheme. For example, the Scheme name of Telegram is set to tg and for Instagram, it is set to Instagram. You can view a list of popular apps [here](اینجا.

Adding initial init Sibche libraryه

local SibcheStoreKit = require "sibche.wrapper"

SibcheStoreKit.init(YOUR_API_KEY, YOUR_SCHEME)

First you need to enter the sibche plugin and recall the init method using the following code



Instead of YOUR_API_KEY, you must enter the api key which you received from the Sibche developer panel. Also, instead of YOUR_SCHEME, you must enter the scheme which was defined in the previous stages.

Available objects of use for the sibche plugin (corona):

In order to buy, activate and use Sibche packages, the following objects (table) have been created. Some explanations regarding each of them will be presented in the following: - SibchePackage: this class represents the purchasable package which was defined in the developer panel. - SibchePurchasePackage: this class represents the corresponding purchase of a user which has been assigned to a SibchePackage. This class consists of the purchase information, time of purchase, expiry date etc. - SibcheError: this class will be referred to you should an error occur and will provide more information regarding the occurred error(s).

SibchePackage

There are three types of package available: - SibcheConsumablePackage: consumable packages which can be used in games or programs, like a 500 gold coin package or in program currency. These packages will remain active and valid until they are consumed and one can repurchase them once they run out. - SibcheNonConsumablePackage: these packages cannot be gradually used and can only be purchased once, like packages which unlock the ability to upload an avatar or change your username. These packages can only be bought once and will remain in the user’s account forever. - SibcheSubscriptionPackage: packages which have a limited time of use. After the time runs out, the user can no longer make use of them. For example, packages which grant the use of special options for only one year.


sibchePackage.packageId (string)
sibchePackage.type (string)
sibchePackage.code (string)
sibchePackage.name (string)
sibchePackage.packageDescription (string)
sibchePackage.price (int)
sibchePackage.totalPrice (int)
sibchePackage.discount (int)

All of these objects fall under the umbrella object, SibchePackage and include the following functions:







sibchePackage.duration (int)
sibchePackage.group (string)

also, the SibcheSubscriptionPackage object includes the following additional functions:

SibchePurchasePackage

sibchePurchasePackage.purchasePackageId (string)
sibchePurchasePackage.type (string)
sibchePurchasePackage.code (string)
sibchePurchasePackage.expireAt ()
sibchePurchasePackage.createdAt ()
sibchePurchasePackage.package (SibchePackage)

This object includes the user’s purchases corresponding with your packages. This object includes the following functions:


SibcheError

event.errorMessage;
event.errorCode;
event.errorStatusCode;

This object will be provided to you should an error occur in the same parameter callback and has the following features:

ErrorCode number Reason
1000 Unknown reason
1001 This package has been already purchased
1002 User has quit the process
1003 Login error
1004 Program has not initiated properly

How to get the list of available packages (corona)

local function fetchInAppPurchasePackagesCallback(event)
    print(inspect(event))
    if(event.isSuccessful) then
        -- success block: e.g. fill packages with event.packagesArray
    else
        -- failure block: e.g. show error to user based on event.errorCode
    end
end

SibcheStoreKit.fetchInAppPurchasePackages(fetchInAppPurchasePackagesCallback)

After tuning the options for the program, you can view the available packages. You must simply use the following code in order to receive the function of interest:




If successful, the developer kit will provide you with the available package plugins in the form of an answer parameter. This parameter is an array of the packages which are available for purchase. These packages are of the SibchePackage kind.

In case the request is not successful, parameters called errormessage, errorcode and errorstatuscode will be sent. If such is not the case, null will be sent.

How to get package information (corona)

local function fetchInAppPurchasePackageCallback(event)
    print(inspect(event))
    if(event.isSuccessful) then
        -- success block: e.g. use event.package into your game
    else
        -- failure block: e.g. show error to user based on event.errorCode
    end
end

SibcheStoreKit.fetchInAppPurchasePackage(ِYOUR_PACKAGE_ID_OR_CODE, fetchInAppPurchasePackageCallback)

If you have the bundle code or ID of the package, you can obtain its information. The following is how to use this API:



The parameter presented secondly is the very callback that we sent which, after getting checked, was recalled. If successful, the package of interest will be sent to you in the object form of SibchePackage.

How to purchase a package (corona):

local function purchasePackageCallback(event)
    print(inspect(event))
    if(event.isSuccessful and event.purchasePackage) then
        -- success block
    else
        -- failure block
    end
end

SibcheStoreKit.purchasePackage(ِYOUR_PACKAGE_ID_OR_CODE, purchasePackageCallback)

After obtaining the package list, you can use the following code in order to set a purchase request to the plugin. Next, the developer kit will, if necessary, log the client in and check up on the payment procedure. Then, it will tell you if the purchase has been successful or not and will provide you with a SibchePurchasePackage.

How to obtain the list of previous purchases (corona)

local function fetchActiveInAppPurchasePackagesCallback( event )
    print(inspect(event))
end

SibcheStoreKit.fetchActiveInAppPurchasePackages(fetchActiveInAppPurchasePackagesCallback)

You can use the following code to obtain your active (purchased) packages. Just simply call in the developer kit function as in the following code.


In response, the kit will provide you with information as to whether the request was successful or not, as well as an array of active purchased packages. Take note that this array is of the SibchePurchasePackage kind.

Active packages are those which have not yet run out of time or have not been used up completely. The Sibche definition for active packages for each of the package types is as follows: - SibcheConsumablePackage: packages which have been purchased but have not yet been consumed. - SibcheNonConsumablePackage: packages which can be bought once and therefore will remain active forever. - SibcheSubscriptionPackage: packages which still have time until their expiry date.

Using up packages on the part of the client (corona)

local function consumePurchasePackageCallback( event )
    print(inspect(event))
end

local function purchasePackageCallback( event )
    print(inspect(event))
    if(event.isSuccessful and event.purchasePackage) then
        if(event.purchasePackage.package.type == "ConsumableInAppPackage") then
            SibcheStoreKit.consumePurchasePackage(event.purchasePackage.purchasePackageId, consumePurchasePackageCallback)
        end
    end
end

SibcheStoreKit.purchasePackage(ِYOUR_PACKAGE_ID_OR_CODE, purchasePackageCallback)

In order to use the consumable packages, you must recall the associated function from the developer kit, similar to the following code:




In response, after the request status has been checked, the developer kit will recall the requested callback. If it is successful, it means that the package has been used up successfully, but if it is unsuccessful, it means that an error has occurred in the usage procedure.

Using up packages on the part of the server(corona):

To do this, you must have purchasePackageId which is part of the SibchePurchasePackage class. Then, you must make a link similar to the following and receive the verification data from the server (addresses are case sensitive!): https://api.sibche.com/sdk/userInAppPurchasePackages/{purchasePackageId}/verifyConsume

Also, the HTTP header must be set onto the App-Key for this operation. This key is available for any specific program through the developer panel. This key is called the server key and has 30 characters.

curl --header "App-Key: YOUR_SERVER_KEY" -X POST \
'https://api.sibche.com/sdk/userInAppPurchasePackages/1/verifyConsume'

A sample of code which can be recalled for curl can be as follows:



In response, the server will provide one of these HTTP Response Codes:

this occurs either when you misspell the address link or package, or if the package has already been used. In this case the server will respond with something like this code:

{
  "message" : "your package is already is used or not found",
  "status_code" : 404
}

this means that the server key which has been set on the app-key is invalid or wrong. In this case, the server will provide a similar response to the following:

{
  "message" : "app-key is not valid",
  "status_code" : 401
}

Client login request to the Sibche developer kit (corona)

local function loginCallback(event)
    print(inspect(event))
end

SibcheStoreKit.loginUser(loginCallback)

By using this code, you can send a login request to the Sibche library. All you need to do is, as it is done below, recall the function relating to the developer kit.


In response, the plugin will provide information regarding the successfulness of the login and the errors it faced in the process. Also, it will recall the client’s ID and username if the process was successful and the items exist in the database.

How to logout of the Sibche developer kit (corona)

local function logoutCallback(event)
    print(inspect(event))
end

SibcheStoreKit.logoutUser(logoutCallback)

By the use of this code, you can logout the client who is already logged in to the plugin and delete their session information. This function will provide a response to you in the form of a callback.

How to obtain information on current clients (corona)

local function getCurrentUserCallback(event)
    print(inspect(event))
end

SibcheStoreKit.getCurrentUserData(getCurrentUserCallback)

When you need to get the client’s phone number and userID you can use the following function:




In response, the developer kit will tell you if the process was successful or not and also recalls the error that may have occurred. In most cases the process will go smoothly, but in some rare cases, the following reasons could be why the process wasn’t successful: - Connectivity issues - Network issues - Sibche server is not accessible

In addition, a third parameter exists which tells you whether the client is logged in or not. if the client is logged in, the response type will be of this kind loginStatusTypeIsLoggedIn. If they are not logged in, the response type will be of the loginStatusTypeIsLoggedOut kind. If the process is not successful and we are not sure whether the client is logged in or not, we will get a response which is of the loginStatusTypeHaveTokenButFailedToCheck kind. The next parameters in the received response will include the client’s phone number and ID.

How to install the react native developer kit

install requirements

  1. Uploading the app in Sibche Developer Dashboard
  2. Receiving app key from Dashboard
  3. Latest version of Xcode

Installing the react native developer kit:

Simply run the following code in you react project. This will install the sibche package on your project.

npm install --save react-native-sibche-storekit

## OR

yarn add react-native-sibche-storekit

Then install Sibche Plugin using pod:

pod repo update
pod install

Default settings:

Adding your app’s exclusive Scheme

In order to add exclusive Scheme, you need to open the settings in Xcode and go to “info” tab as such:

Then, like so, add your app’s URL in the field:

Chose a name and put it in the testapp field, this name will be the name of your Scheme. For example, the Scheme name of Telegram is set to tg and for Instagram, it is set to Instagram. You can view a list of popular apps here.

How to add the developer kit to AppDelegate

First, add the developer kit activation code into the following function: didFinishLaunchingWithOptions (in order to view the code for this stage you need to select Objective-C from the language tab above)

#import "AppDelegate.h"
#import <SibcheStoreKit/SibcheStoreKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [SibcheStoreKit initWithApiKey:YOUR_API_KEY withScheme:YOUR_SCHEME];

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"CallRecorder"
                                            initialProperties:nil];
  ...
}                                            

It is noteworthy that you should insert the program key obtained from the Sibche developer panel in the place of YOUR_API_KEY. Also, the word scheme, which was added in the previous stage, must be placed instead of YOUR_SCHEME.

Then, give the developer kit the permission to open urls:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  [SibcheStoreKit openUrl:url options:nil];
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

Available classes of use for the developer kit:

In order to buy, activate and use Sibche packages, the following classes have been created. Some explanations regarding each of them will be presented in the following:

SibchePackage

There are three types of package available:

All of these packages fall under the umbrella package, SibchePackage and include the following functions:

{
    packageId: string,
    type: string,
    code: string,
    name: string,
    packageDescription: string,
    price: number,
    totalPrice: number,
    discount: number
}









also, the SibcheSubscriptionPackage includes the following additional functions:

{
    duration: number,
    group: string
}


SibchePurchasePackage

This package includes the user’s purchases corresponding with your packages. This class includes the following functions:

{
    purchasePackageId: string,
    type: string,
    code: string,
    expireAt: number,
    createdAt: number,
    package: SibchePackage
}




SibcheError

{
    errorCode: number,
    message: string,
    statusCode: number
}

You will be provided with this class should an error with the following characteristics occur:



ErrorCode number Reason
1000 Unknown reason
1001 This package has been already purchased
1002 User has quit the process
1003 Login error
1004 Program has not initiated properly

How to get the list of available packages:

After tuning the options for the program, you can view the available packages. You must simply use the following code in order to receive the function of interest:

import SibcheStoreKit from "react-native-sibche-storekit";


SibcheStoreKit.fetchInAppPurchasePackages((isSuccessful, error, packagesArray) => {
    console.log(isSuccessful, error, packagesArray);
});


If successful, the developer kit will provide you with the available packages in the form of a parameter. This parameter is an array of the packages which are available for purchase. These packages are of the SibchePackage kind.

In case the request is not successful, a parameter called error, which is of the SibcheError kind, will be sent.

How to get package information:

If you have the bundle code or ID of the package, you can obtain its information. The following is how to use this API:

SibcheStoreKit.fetchInAppPurchasePackage(PACKAGE_ID_OR_CODE, (isSuccessful, error, packageItem) => {
    console.log("=====> specific package", isSuccessful, error, packageItem);
});


The initially presented parameter is the very callback that we sent which, after getting checked, was recalled. If successful, the package of interest will be sent to you in the object form of SibchePackage.

How to purchase a package

After obtaining the package list, you can use the following code in order to set a purchase request through the developer kit. Next, the kit will, if necessary, log the client in and check up on the payment procedure. Then, it will tell you if the purchase has been successful or not and will provide you with a SibchePurchasePackage.

SibcheStoreKit.purchasePackage("ava.test", (isSuccessful, error, purchasePackage) => {
    console.log("Result of purchase", isSuccessful, error, purchasePackage);
    if (isSuccessful) {
        // Success block
    }else{
        // Failure block
    }
});


How to obtain the list of previous purchases:

You can use the following code to obtain your active (purchased) packages. Just simply call in the developer kit function as in the following code.

SibcheStoreKit.fetchActiveInAppPurchasePackages((isSuccessful, error, purchasePackagesArray) => {
    console.log("=====> Active pacakges", isSuccessful, error, purchasePackagesArray);
});



In response, the kit will provide you with information as to whether the request was successful or not, as well as an array of active purchased packages. Take note that this array is of the SibchePurchasePackage kind.


Active packages are those which have not yet run out of time or have not been used up completely. The Sibche definition for active packages for each of the package types is as follows:

Using up packages on the part of the client:

In order to use the consumable packages, you must recall the associated function from the developer kit, similar to the following code:

SibcheStoreKit.consumePurchasePackage(purchasePackage.purchasePackageId, (isSuccessful, error) => {
    console.log("Result of consume", isSuccessful, error);
});

In response, after the request status has been checked, the developer kit will recall the requested callback. If it is successful, it means that the package has been used up successfully, but if it is unsuccessful, it means that an error has occurred in the usage procedure.

Using up packages on the part of the server:

To do this, you must have purchasePackageId which is part of the SibchePurchasePackage class. Then, you must make a link similar to the following and receive the verification data from the server (addresses are case sensitive!):

https://api.sibche.com/sdk/userInAppPurchasePackages/{purchasePackageId}/verifyConsume

Also, the HTTP header must be set onto the App-Key for this operation. This key is available for any specific program through the developer panel. This key is called the server key and has 30 characters.

A sample of code which can be recalled for curl can be as follows:

curl --header "App-Key: YOUR_SERVER_KEY" -X POST \
'https://api.sibche.com/sdk/userInAppPurchasePackages/1/verifyConsume'



In response, the server will provide one of these HTTP Response Codes:

{
  "message" : "your package is already is used or not found",
  "status_code" : 404
}



Client login request to the Sibche developer kit

SibcheStoreKit.loginUser((isSuccessful, error, userName, userId) => {
    if (isSuccessful) {
        // Successful login
    }else{
        // Failed login
    }
})

By using this code, you can send a login request to the Sibche library. All you need to do is, as it is done below, recall the function relating to the developer kit.



In response, the developer kit will provide information regarding the successfulness of the login and the errors it faced in the process.

How to logout of the Sibche developer kit:

SibcheStoreKit.logoutUser(() => {
    console.log("Logging out finished");
})

By the use of this code, you can logout the client who is already logged in to the developer kit and delete their session information. This function will provide a response to you in the form of a callback.

How to obtain information on current clients:

When you need to get the client’s phone number and userID you can use the following function:

SibcheStoreKit.getCurrentUserData((isSuccessful, error, loginStatus, userCellphoneNumber, userId) => {
    console.log("Get current user data", isSuccessful, error, loginStatus, userCellphoneNumber, userId);
})



In response, the developer kit will tell you if the process was successful or not and also recalls the error that may have occurred. In most cases the process will go smoothly, but in some rare cases, the following reasons could be why the process wasn’t successful:

In addition, a third parameter exists which tells you whether the client is logged in or not. if the client is logged in, the response type will be of this kind loginStatusTypeIsLoggedIn. If they are not logged in, the response type will be of the loginStatusTypeIsLoggedOut kind. If the process is not successful and we are not sure whether the client is logged in or not, we will get a response which is of the loginStatusTypeHaveTokenButFailedToCheck kind. The next parameters in the received response will include the client’s phone number and ID.