BasSdk 5.1.2

dotnet add package BasSdk --version 5.1.2
                    
NuGet\Install-Package BasSdk -Version 5.1.2
                    
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="5.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BasSdk" Version="5.1.2" />
                    
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 5.1.2
                    
#r "nuget: BasSdk, 5.1.2"
                    
#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@5.1.2
                    
#: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=5.1.2
                    
Install as a Cake Addin
#tool nuget:?package=BasSdk&version=5.1.2
                    
Install as a Cake Tool

BasSdk - Payment Method Integration Guide

Overview

BasSdk is a .NET Standard library designed for merchants who want to use BAS as a payment method in their independent mobile applications (similar to integrating PayPal or Stripe).

This guide covers the usage of IBasPaymentMethodService, which provides optimized SDK endpoints for seamless payment integration.

Initialization

Before using the service, you must initialize it with your merchant credentials and environment settings. This ensures the service knows how to connect to the BAS platform.

using BasSdk.Constants;
using BasSdk.Services;

public class PaymentService
{
    private readonly IBasPaymentMethodService _paymentService;
    
    public PaymentService(IBasPaymentMethodService paymentService)
    {
        _paymentService = paymentService;
        
        // 1. Initialize credentials
        _paymentService.Initialize(
            environment: LibraryConstants.ENVIRONMENT.SANDBOX, // SANDBOX, STAGING, or PRODUCTION
            mid: "your_merchant_id", 
            appId: "your_app_id", 
            clientId: "your_client_id", 
            clientSecret: "your_client_secret", 
            website: "your_website_url", 
            callbackUrl: "your_callback_url", 
            defaultRequestTimeOut: 60
        );

        // 2. (Optional) Enable built-in logging
        _paymentService.EnableLoggingInformation();

        // 3. (Optional) Hook your own logger
        _paymentService.SetLogActions(
            logInformation: (message) => 
            {
                Console.WriteLine($"[BasSdk Info]: {message}");
                return true;
            },
            logError: (exception, message) => 
            {
                Console.WriteLine($"[BasSdk Error]: {message} - {exception.Message}");
                return true;
            }
        );
    }
}

Installation

To install the package, use the following command in the NuGet Package Manager Console or .NET CLI:

# NuGet Package Manager
Install-Package BasSdk

# .NET CLI
dotnet add package BasSdk

Dependency Injection Registration

Register the SDK service in your dependency injection container:

// In your Startup.cs or Program.cs
services.AddBasSdk(); 

// Or if you only want to register the specific service
// services.AddTransient<IBasPaymentMethodService, BasPaymentMethodService>();

Payment Flow

The payment flow consists of two main steps from your backend's perspective:

  1. Initiate Payment
  2. Check Transaction Status

1. Initiate Transaction

This is the first step to initiate a payment. It returns a transaction token that you must pass to your independent mobile application to launch the BAS SDK UI and complete the payment.

var response = await _paymentService.InitiateTransactionSdkAsync(
    orderId: "ORDER_12345", 
    amount: 2000, 
    currency: "YER", 
    customerId: "customer_open_id",
    customerPhone: "+967123456789", // Optional
    customerName: "John Doe",       // Optional
    requestTimeout: 60,
    orderDetails: new
    {
        products = new List<object>
        {
            new { name = "Product 1", quantity = 1, price = 2000 }
        }
    }
);

if (response.Status != 1)
{
    // Handle error
    throw new InvalidOperationException(response.Messages.FirstOrDefault());
}

// Extract the transaction token and send it to your mobile app
string transactionToken = response.Body.TrxToken;

2. Check Transaction Status

After your mobile application completes the payment flow (using the transactionToken), you should verify the exact final status of the transaction on your backend.

var statusResponse = await _paymentService.CheckTransactionStatusSdkAsync(
    orderId: "ORDER_12345", 
    requestTimeout: 60
);

if (statusResponse.Status != 1)
{
    throw new InvalidOperationException(statusResponse.Messages.FirstOrDefault());
}

// TrxStatusId == 1202 means the payment was processed successfully
if (statusResponse.Body.TrxStatusId == 1202) 
{
    Console.WriteLine("Payment was successful!");
}
else
{
    Console.WriteLine($"Payment status is: {statusResponse.Body.TrxStatus}");
}

Refund a Payment

You can refund a full payment amount by providing the original trxToken and a reason for the refund.

var refundResponse = await _paymentService.FullPaymentRefundAsync(
    trxToken: "TRX_TOKEN_FROM_INITIATE",
    reason: "Customer requested a refund"
);

if (refundResponse.Status != 1)
{
    throw new InvalidOperationException(refundResponse.Messages.FirstOrDefault());
}

Console.WriteLine("Refund processed successfully!");

Support

For issues specific to the payment method integration or SDK functions, please verify your initialization settings or contact the Bas Team for support.

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.