# ezetap_sdk

[![pub package](https://img.shields.io/pub/v/ezetap_sdk.svg)](https://pub.dev/packages/ezetap_sdk)
[![pub points](https://img.shields.io/pub/points/ezetap_sdk?color=2E8B57&label=pub%20points)](https://pub.dev/packages/ezetap_sdk/score)

Welcome to Ezetap Payments Flutter SDK integration! You can easily collect payments from your
existing android applications by integrating the SDK.

## How integration works

1. Include the SDK in your mobile application to collect payments.
2. SDK interfaces with a Service App, this App will be installed during run-time.
3. Service App interfaces with the Card Device and Ezetap Servers to finish payment processing and
   notifies the status to SDK.

## Prerequisites

Supported on Android API version 21 or above.

## Use this package as a library

This will add a line like this to your package's pubspec.yaml (and run an
implicit ```flutter pub get```)

```
dependencies:
  ezetap_sdk: ^0.2.5
```

## Import it

Now in your Dart code, you can use:

```import 'package:ezetap_sdk/ezetap_sdk.dart';```

## Methods Available

```javascript
 var json = {
      "prodAppKey": "Your prod app key",
      "demoAppKey": "Your demo app key",
      "merchantName": "merchantName",
      "userName": "userName",
      "currencyCode": 'INR',
      "appMode": "Your environment",
      "captureSignature": 'true',
      "prepareDevice": 'false',
      "captureReceipt": 'false'
    };
  
  EzetapSdk.initialize(json);
```
```javascript
  EzetapSdk.prepareDevice();
```
```javascript
  var sendReceiptJson = {
      "customerName": "customerName",
      "mobileNo": "mobileNo",
      "email": "emailId",
      "txnId": "transactionID"
    };
    
  EzetapSdk.sendReceipt(sendReceiptJson);
```
```javascript
    var json = {
      "issueType": "issueType",
      "issueInfo": "issueInfo",
      "tags": [
        "tag1","tag2"
      ]
    };

  EzetapSdk.serviceRequest(json);
```
```javascript
    var json = {
      "agentName": "username",
      "saveLocally": false
    };

  EzetapSdk.searchTransaction(json);
```
```javascript
   var json = {
      "amount": "100",
      "options": {
        "amountTip": 0.0,
        "references": {
          "reference1": "sffr",
          "additionalReferences": [
    
          ]
        },
        "customer": {
    
        },
        "serviceFee": -1.0,
        "addlData": {
          "addl1": "addl1",
          "addl2": "addl2",
          "addl3": "addl3"
        },
        "appData": {
          "app1": "app1",
          "app2": "app2",
          "app3": "app3"
        }
      }
    };

  EzetapSdk.getTransaction(json);
```
```javascript
   var json = {};
  EzetapSdk.checkForIncompleteTransaction(json);
  ```
  ```javascript
  //Pass the transactionId to this function
  EzetapSdk.voidTransaction(String transactionID);
```
```javascript
   var json = {"txnId": "transactionID"};
  EzetapSdk.attachSignature(json);
```
```javascript
var json = {
  "amount": "123",
  "options": {
    "serviceFee": 100,
    “payToAccount”: “LABEL”,
    "paymentBy": "CREDIT OR DEBIT OR ANY (**To be used only if the service fee is being added.)",
    "paymentMode": "Card/Cash/Cheque/UPI/UPI_VOUCHER/RemotePay/BHARATQR/Brand_Offers/Brand_EMI/Normal_EMI/Wallet ",
    "providerName": "<NBFC> eg. ZestMoney. (**providerName and emiType are to be passed only if user wants to use ZestMoney. In this scenario, set \"paymentMode”:”EMI”)",
    "emiType": "NORMAL, BRAND, EMI",
    "references": {
      "reference1": "1234",
      "additionalReferences": [
        "addRef_xx1",
        "addRef_xx2"
      ]
    },
    "appData": {
      "walletAcquirer": "freecharge/ola_money/ etc.(**walletAcquirer are to be passed only if user sets \"paymentMode”:”Wallet”)"
    },
    "customer": {
      "name": "xyz",
      "mobileNo": "1234567890",
      "email": "abc@xyz.com"
    }
  }
};
  EzetapSdk.pay(json);
```
```javascript
  //Pass the transactionId to this function
  EzetapSdk.printReceipt(String transactionID);
```
```javascript
  //Pass the image as base64 string to this function
  EzetapSdk.printBitmap(String? base64Image);
```
```javascript
  EzetapSdk.logout();
```
```javascript
  var json = {"txnIds":[""]};
  EzetapSdk.stopPayment(json);
```
```javascript
  EzetapSdk.scanBarcode();
```
```javascript
   var json = {
     "amount": "100",
     "txnId": "transactionID"
   };
  EzetapSdk.refundTransaction(json);
```
```javascript
  EzetapSdk.checkForUpdates();
```
```javascript
  EzetapSdk.checkPrinterStatus();
```
```javascript
  EzetapSdk.printTextReceipt(txtReceipt);
```
```javascript
  EzetapSdk.showReceiptView(jsonEncode(receipt));
```
```javascript
  EzetapSdk.getDeviceInfo();
```

```dart
Future<void> onPaymentClicked(json) async {
  String? result = await EzetapSdk.pay(json);
  if (!mounted) return;
  setState(() {
    _result = result;
  });
}
```
```dart
Future<void> onBarcodePressed() async {
  String? result = await EzetapSdk.scanBarcode();
  if (!mounted) return;
  setState(() {
    _result = result;
  });
}
```
```dart
Future<void> checkPrinterStatus() async {
    String? result = await EzetapSdk.checkPrinterStatus();
    if (!mounted) return;
    setState(() {
      _result = result;
    });
  }
```
```dart
Future<void> printTextReceipt() async {
   var txtReceipt = "-----------------------------------\n" +
           "           Receipt\n" +
           "-----------------------------------\n" +
           "\n" +
           "Date: January 9, 2024\n" +
           "Time: 12:30 PM\n" +
           "\n" +
           "-----------------------------------\n" +
           "\n" +
           "Items Purchased:\n" +
           "1. Item Name        10.00\n" +
           "2. Another Item     15.50\n" +
           "3. Yet Another Item 8.75\n" +
           "\n" +
           "-----------------------------------\n" +
           "\n" +
           "Subtotal:           34.25\n" +
           "Tax (8%):           2.74\n" +
           "Total Amount:       36.99\n" +
           "\n" +
           "-----------------------------------\n" +
           "\n" +
           "Payment Method:     Credit Card\n" +
           "\n" +
           "Card Number:        **** **** **** 1234\n" +
           "Expiry Date:        12/25\n" +
           "Authorization Code: 56789\n" +
           "\n" +
           "-----------------------------------\n" +
           "\n" +
           "Thank you for your purchase!\n" +
           "Please come again.\n" +
           "\n" +
           "-----------------------------------";

   String? result = await EzetapSdk.printTextReceipt(txtReceipt);
   if (!mounted) return;
   setState(() {
      _result = result;
   });
}
```
```dart
Future<void> showCustomReceiptView() async {
    final ByteData data = await rootBundle.load('assets/logo.png');
    final Uint8List bytes = data.buffer.asUint8List();
    ui.decodeImageFromList(bytes, (ui.Image img) async {
      ByteData? byteData = await img.toByteData(format: ui.ImageByteFormat.png);
      var receipt = [
        base64.encode(byteData?.buffer.asUint8List() as List<int>),
        "<div class=\"item\" style=\"text-align: center;\"><span style=\"font-size: 34;\"><big>Heading</big></span></div>",
        "<div class=\"item\"><span>Date:</span> <span>2024-02-12</span></div>",
        "<div class=\"item\"><span>Time:</span> <span>15:30</span></div>",
        "<div class=\"item\"><span>Receipt No:</span> <span>123456</span></div>",
        "<div class=\"item\"><span>Items:</span><ul><li>Item 1 - \$10</li><li>Item 2 - \$20</li><li>Item 3 - \$15</li></ul></div>",
        "<div class=\"item\"><span>Total:</span> <span>\$45</span></div>",
        "<div class=\"item\"><span>Date:</span> <span>2024-02-12</span></div>",
        "<div class=\"item\"><span>Time:</span> <span>15:30</span></div>",
        "<div class=\"item\"><span>Receipt No:</span> <span>123456</span></div>",
        "<div class=\"item\"><span>Items:</span><ul><li>Item 1 - \$10</li><li>Item 2 - \$20</li><li>Item 3 - \$15</li></ul></div>",
        "<div class=\"item\"><span>Total:</span> <span>\$45</span></div>",
        "<div class=\"item\"><span>Date:</span> <span>2024-02-12</span></div>",
        "<div class=\"item\"><span>Time:</span> <span>15:30</span></div>",
        "<div class=\"item\"><span>Receipt No:</span> <span>123456</span></div>",
        "<div class=\"item\"><span>Items:</span><ul><li>Item 1 - \$10</li><li>Item 2 - \$20</li><li>Item 3 - \$15</li></ul></div>",
        "<div class=\"item\"><span>Total:</span> <span>\$45</span></div>",
        "<div class=\"item\"><span>Date:</span> <span>2024-02-12</span></div>",
        "<div class=\"item\"><span>Time:</span> <span>15:30</span></div>",
        "<div class=\"item\"><span>Receipt No:</span> <span>123456</span></div>",
        "<div class=\"item\"><span>Items:</span><ul><li>Item 1 - \$10</li><li>Item 2 - \$20</li><li>Item 3 - \$15</li></ul></div>",
        "<div class=\"item\"><span>Total:</span> <span>\$45</span></div>",
        base64.encode(byteData?.buffer.asUint8List() as List<int>)
      ];
      try {
        String? result = await EzetapSdk.showReceiptView(jsonEncode(receipt));
        if (!mounted) return;
        setState(() {
          _result = result;
        });
      } on PlatformException catch (e) {
        if (!mounted) return;
        setState(() {
          _result = e.message.toString();
        });
      }
    });
  }
```
## What you need

1. Flutter development environment
2. Android phone that can connect to internet
3. This documentation
4. Ezetap app key or login credentials to Ezetap service
5. Ezetap device to test card payments

