📜  nagad 官方 api (1)

📅  最后修改于: 2023-12-03 15:17:49.707000             🧑  作者: Mango

Nagad 官方 API

Nagad is a leading mobile financial service provider in Bangladesh. They offer a wide range of services such as sending money, making payments, purchasing airtime and many more. In order to leverage the power of Nagad, they provide developers with an API that allows them to integrate Nagad's services into their applications.

Getting Started

To get started with Nagad API, you need to follow the below steps:

  1. Create an Account: The first step is to create an account with Nagad. You can create an account by visiting their website and signing up. Once you have created an account, Nagad will provide you with an API key and a secret key which will be required to authenticate your API calls.

  2. Read the Documentation: Nagad provides comprehensive documentation for their API which helps developers understand how to integrate Nagad's services into their applications. You can access the documentation by visiting the Nagad API website.

  3. Choose an SDK: Nagad provides SDKs for multiple programming languages such as Java, Python, PHP, .NET, and many more. You can choose an SDK that best suits your development environment.

  4. Integrate Nagad's Services: Once you have your API key, secret key, and SDK ready, you can start integrating Nagad's services into your application. Nagad provides various services such as sending money, making payments, checking balance, etc. You can choose the services that best suit your application and start integrating them.

Example Code Snippets

Here are some code snippets that demonstrate how to use Nagad's API to perform certain tasks:

Send Money
import com.nagad.sdk.ApiClient;
import com.nagad.sdk.ApiException;
import com.nagad.sdk.Configuration;
import com.nagad.sdk.auth.JWTAuth;
import com.nagad.sdk.model.SendMoneyRequest;
import com.nagad.sdk.model.SendMoneyResponse;

public class SendMoneyExample {
    public static void main(String[] args) {
        JWTAuth jwtAuth = new JWTAuth("API_KEY", "SECRET_KEY");
        ApiClient apiClient = Configuration.getDefaultApiClient();
        apiClient.setBasePath("https://nagad.com.bd");
        apiClient.setDebugging(true);
        apiClient.setApiKey(jwtAuth);
        apiClient.setApiKeyPrefix("Bearer");

        SendMoneyRequest request = new SendMoneyRequest();
        request.setFrom("017XXXXXXXX");
        request.setTo("017XXXXXXXX");
        request.setAmount("100");
        request.setPurpose("test");

        try {
            SendMoneyResponse response = apiClient.sendMoney(request);
            System.out.println(response);
        } catch (ApiException e) {
            System.err.println(e.getResponseBody());
        }
    }
}
Make Payment
import nagad_sdk

# authenticate with Nagad API
nagad_sdk.Configuration.api_secret_key = 'SECRET_KEY'
nagad_sdk.Configuration.access_token = 'API_KEY'

payment_api = nagad_sdk.PaymentApi()

try:
    # make payment
    payment_details_response = payment_api.payment_details(
        '017XXXXXXXX', '100', 'test', 'bd.currency', 'ecommerce', '1020201020211111', '012')
    print(payment_details_response)
except nagad_sdk.ApiException as e:
    print("Exception when calling PaymentApi->payment_details: %s\n" % e)
Check Balance
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$nagadAuth = new Nagad\Api\Auth\NagadAuth("API_KEY", "SECRET_KEY");
$nagad = new Nagad\Api\Nagad($nagadAuth);
try {
    $response = $nagad->checkBalance();
    echo $response;
} catch (Nagad\ApiException $e) {
    echo 'Exception when calling Nagad->checkBalance: ', $e->getMessage(), PHP_EOL;
}
Conclusion

In conclusion, Nagad provides a powerful API that allows developers to integrate their services into their applications. By following the steps outlined in this documentation, you can quickly and easily get started with Nagad API and start leveraging the power of mobile financial services.