BasSdk 2.0.4

Suggested Alternatives

BasSdk 5.1.0

Additional Details

Please update to 5.1.0 because there are major changes for this version

There is a newer version of this package available.
See the version list below for details.
dotnet add package BasSdk --version 2.0.4
                    
NuGet\Install-Package BasSdk -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BasSdk" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BasSdk" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="BasSdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BasSdk --version 2.0.4
                    
#r "nuget: BasSdk, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BasSdk@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BasSdk&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=BasSdk&version=2.0.4
                    
Install as a Cake Tool

BasSdk NuGet Package

Overview

BasMainService is a comprehensive service that provides multiple functionalities, including fetching user information, initiating transactions, checking transaction statuses, sending notifications, and simulating mobile authentication. The service also includes logging capabilities and can be initialized with necessary credentials and environment settings.

Installation

To install the package, use the following command in the NuGet Package Manager Console:

Install-Package BasSdk

Usage

Initialization

Before using the services, you need to initialize the BasMainService class with the required parameters and environment settings. The following code snippet demonstrates how to initialize the service: environment can be LibraryConstants.ENVIRONMENT.SANDBOX or LibraryConstants.ENVIRONMENT.STAGING or LibraryConstants.ENVIRONMENT.PRODUCTION

BasMainService.Initialize(
    environment: LibraryConstants.ENVIRONMENT environment, 
    mid: "your_mid", //merchant key
    appId: "your_app_id", 
    clientId: "your_client_id", 
    clientSecret: "your_client_secret", 
    website: "your_website", 
    callbackUrl: "your_callback_url", 
    defaultRequestTimeOut: 60
);

Enable/Disable Logging

You can enable or disable logging information as needed.

BasMainService.EnableLoggingInformation();
BasMainService.DisableLoggingInformation();

Methods

Authentication flow

1- Mobile Fetch Auth id

Simulates a mobile first step you can call this method to simulate mobile fetch auth_id, this method will return a mocked response from mobile app to backend for debugging purpose when environment is Sandbox

Task<BasBaseResponse<FetchAuthMobileResponseModel>> SimulateMobileFetchAuthAsync(string clientId, int requestTimeout = 60)

Example:

//to mock (simulate) mobile fetch auth step you can call below function (this should be only for testing purpose  when environment is sandbox)
var mockedMobileResponse = await _basMainService.SimulateMobileFetchAuthAsync(clientId);
if (mockedMobileResponse.Status != 1)
{
    //handle error case 
    var error = mockedMobileResponse.Messages.FirstOrDefault();
    throw new InvalidOperationException(error);
}
2- Get User Info

Fetches user information from the backend.

The function will return a Task<BasBaseResponse<UserInfoDataResponse>> object, you can use this object to get the user information

Task<BasBaseResponse<UserInfoDataResponse>> GetUserInfoAsync(string code, int? requestTimeOut = null, Dictionary<string, string> headerExtraInfo = null)

you can call this method to get user information from backend

var authId=<authId from Mobile Response>;
var userInfoResp = await _basMainService.GetUserInfoAsync(authId)
if (userInfoResp.Status != 1)
{
    //handle error case
    await _logger.ErrorAsync($"Error when get user info  response is :{JsonConvert.SerializeObject(userInfoResp)}");
    throw new InvalidOperationException(userInfoResp.Messages.FirstOrDefault());
}
var userName = userInfoResp.Data.user_name;
var email = userInfoResp.Data.email;
var phone = userInfoResp.Data.phone;
var name = userInfoResp.Data.name;
var openId = userInfoResp.Data.open_id;
...your rest of code

Payment flow

1- Initiate Transaction

This is first step to initiate payment (should be called from backend), this function will return a Task<ResponseSig<InitiateTransactionResponse>> object, you can use this object to get the transaction token

    Task<ResponseSig<InitiateTransactionResponse>> InitiateTransactionAsync(string orderId, decimal amount, string currency, string customerId, int requestTimeout = 60, object orderDetails = null, Dictionary<string, object> extraFields = null, string callbackUrl = null)       

Example:


ResponseSig<InitiateTransactionResponse> response = await _basMainService.InitiateTransactionAsync("abc123", 2000, "YER", "openId", orderDetails: new
{
    products = new List<object>
    {
        new
        {
            name = "product1",
            quantity = 1,
            price = 2000
        }
    }
});
if (response.Status != 1)
{
    //handle error case (you can get the error message from response.Messages.FirstOrDefault())
    throw new InvalidOperationException(response.Messages.FirstOrDefault());
}
//extract the transaction token from response.Body.TrxToken and return it to mobile app
var responseToMobile = new
{
    amount = new { value = orderTotal.ToString(), currency = "YER" },
    orderId = orderId,
    trxToken = response.Body.TrxToken,
    appId = BasMainService.GetAppId()
};
... your rest of code
2- Initiate Payment (Mobile)

This is second step to initiate payment (should be called from mobile app), this function will return a BasBaseResponse<MobilePaymentResponseModel> object, you can use this object to get the transaction token

    public async Task<BasBaseResponse<FetchAuthMobileResponseModel>> SimulateMobilePaymentAsync(MobilePaymentRequest request, int requestTimeout = 60)

Example:

    //to mock (simulate) mobile payment step you can call below function (this should be only for testing purpose  when environment is sandbox)
    var mobileMockedResponse = await _basMainService.SimulateMobilePaymentAsync(new BasSdk.Models.MobileMockModels.MobilePaymentRequest
    {
        amount = new BasSdk.Models.MobileMockModels.MobilePaymentRequest.AmountDto { value = orderTotal.ToString(), currency = targetCurrencyCode },
        orderId = orderId,
        trxToken = response.Body.TrxToken,
        appId=BasMainService.GetAppId()
    });
    if (mobileMockedResponse.Status != 1)
    {
        //handle error case for response comming from mobile app
        throw new InvalidOperationException(mobileMockedResponse.Messages.FirstOrDefault());
    }
3- CheckTransactionStatusAsync

This is third step: to check transaction status (should be called from backend), this function will return a Task<ResponseSig<TrxStatusModel>> object, you can use this object to get the transaction status

Task<ResponseSig<TrxStatusModel>> CheckTransactionStatusAsync(string orderId, int requestTimeout = 60)

Example:

  var checkStatusResponse = await _basMainService.CheckTransactionStatusAsync(orderId, _requestTimeout);
    if (checkStatusResponse.Status != 1)
    {
        //handle error case (you can get the error message from checkStatusResponse.Messages.FirstOrDefault())
        throw new InvalidOperationException(checkStatusResponse.Messages.FirstOrDefault());
    }
    if (checkStatusResponse.Body.TrxStatusId== 1202)
    {
        //when checkStatusResponse.Body.TrxStatusId == 1202 then the payment is succeed ( checkStatusResponse.Body.TrxStatus =="processed")
        await LogInformationAsync($"Payment was Succeed");
    }
SendNotificationToCustomer

Sends a notification to the customer related to order (you can call this method to send notification to customer about delivery status, etc.).

Task<BasBaseResponse> SendNotificationToCustomerAsync(string templateName, string orderId, object orderParams = null, object firebasePayload = null, object extraPayload = null, int requestTimeout = 60)

The templateName is the name of the template that you want to send to the customer (required), orderId is the order id related to this notifiction (required), orderParams is object that contains template parameters (optional depending on the template), firebasePayload is object that contains firebase payload ex:deepLink, etc. (optional) extraPayload is object that contains extra payload that you want to send it to your miniApp as query string(optional)

Example:

//send notification to customer
var notificationResponse = await _basMainService.SendNotificationToCustomerAsync("order_was_shipped", orderId);
if (notificationResponse.Status != 1)
{
    //handle error case
    throw new InvalidOperationException(notificationResponse.Messages.FirstOrDefault());
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributions

Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss any changes.

Contact

For support, please contact Bas Team.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.