Zai Functions

⚡️ Leverage Zai for enhanced functionality.

This guide explains the configuration of Zai functions, C.createZaiCharge, C.refundZaiCharge, and C.listZaiUsers. These functions enable you to create transaction charges and initiate refunds when necessary.


1. C.createZaiCharge

The createZaiCharge function allows you to create a charge for a transaction. Here's an example of how to configure this function:

async function script(C) {
    const response = await C.createZaiCharge({
        data: {
            name: "Test charge from workflow",
            account_id: "0ac944f0-e32c-013b-725d-0a58a9feac03",
            amount: 4200,
            email: "[email protected]",
            zip: 3000,
            country: "AUS",
            currency: "AUD",
            user_id: "demo-testing-1",
            custom_descriptor: "229",
        },
    });
    C.addJsonToSummary(response, {enableCopy: true})
}

Output

The response from this function provides valuable information about the charge creation process, such as payload.charges.id, amount, etc. See the API response reference.

❗️

Note:

Please note that a success response from C.createZaiCharge indicates the creation of a charge, the actual payment may not be processed immediately. Zai will call the provided webhook URL when the charge is processed.


2. C.refundZaiCharge

The refundZaiCharge function is used to initiate a refund for a specific charge. Here's an example of how to configure this function:

async function script(C) {
    const response = await C.refundZaiCharge({
        itemId: "aeb114f9-bb86-4702-984d-f518df52d4d0", 
            
params: { 
        refundAmount: 1050; 
        refundMessage: "Your booking for course: C122 has been cancelled. Amount $10.50 has been refunded"; 
        accountId: "0ac944f0-e32c-013b-725d-0a58a9feac03"; 
    };

    });
    C.addJsonToSummary(response, {enableCopy: true})
}

Output

The response from refundZaiCharge provides information about the refund process and the refunded amount. Here's an example of the response:

{
  "success": true,
  "payload": {
      "id": "7190770-1-2908",
      "name": "Item 7190770-1-2908",
      "description": "Test Item 7190770-1-2908",
      "custom_descriptor": null,
      "payout_descriptor": null,
      "created_at": "2020-05-11T10:26:49.660Z",
      "updated_at": "2020-05-11T10:26:49.660Z",
      "state": "pending",
      "net_amount": 102,
      "chargedback_amount": 0,
      "refunded_amount": 0,
      "released_amount": 0,
      "seller_url": "",
      "buyer_url": "",
      "remaining_amount": 102,
      "status": 22000,
      "amount": 102,
      "payment_type_id": 2,
      "due_date": null,
      "requested_release_amount": 0,
      "pending_release_amount": 0,
      "dynamic_descriptor": null,
      "invoice_url": null,
      "deposit_reference": "100014012533386",
      "buyer_fees": 0,
      "seller_fees": 0,
      "credit_card_fee": 0,
      "direct_debit_fee": 0,
      "paypal_fee": 0,
      "promisepay_fee": 1,
      "batch_state": null,
      "total_outstanding": 102,
      "total_amount": 102,
      "currency": "AUD",
      "payment_method": "pending",
      "buyer_name": "Neol Buyer",
      "buyer_email": "[email protected]",
      "buyer_country": "AUS",
      "seller_name": "Assembly seller71718579",
      "seller_email": "[email protected]",
      "seller_country": "AUS",
      "payment_credit_card_enabled": true,
      "payment_direct_debit_enabled": true,
      "tds_check_state": null,
      "related": {
        "buyers": "buyer-719013950014",
        "sellers": "seller-71718579"
      },
      "links": {
        "self": "/items/7190770-1-2908/refund",
        "buyers": "/items/7190770-1-2908/buyers",
        "sellers": "/items/7190770-1-2908/sellers",
        "status": "/items/7190770-1-2908/status",
        "fees": "/items/7190770-1-2908/fees",
        "transactions": "/items/7190770-1-2908/transactions",
        "batch_transactions": "/items/7190770-1-2908/batch_transactions",
        "wire_details": "/items/7190770-1-2908/wire_details",
        "bpay_details": "/items/7190770-1-2908/bpay_details",
        "tds_checks": "/items/7190770-1-2908/tds_checks"
      }
    }

}

3. C.listZaiUsers

The listZaiUsers function allows you to search and find a user in the Zai database. You can also narrow down the results using parameters such as limit, offset, and search.

ParameterTypeDescription
limitnumber(Optional) Maximum number of users to return. Defaults to 100. Zai enforces a maximum limit of 200.
offsetnumber(Optional) Used for pagination. Usually used together with limit.
searchstring(Optional) A search string that filters users by matching their email or name.

Here’s an example of how to configure this function:

async function script(C) {
    const response = await C.listZaiUsers({
        params: { 
            limit: 2,        
            offset: 0,        
            search: "[email protected]",  
        },
    });

    C.addJsonToSummary(response, { enableCopy: true });
}

Output

The response from listZaiUsers includes a list of users that match the query, along with pagination details and related resource links. Here's an example response:

{
  "success": true,
  "payload": {
    "users": [
      {
        "id": "seller-71460518",
        "full_name": "Assembly seller71460518",
        "first_name": "Assembly",
        "last_name": "seller71460518",
        "created_at": "2020-05-06T07:26:59.479Z",
        "updated_at": "2020-05-06T07:26:59.479Z",
        "email": "[email protected]",
        "mobile": "+1588750018",
        "location": "N/A",
        "links": {
          "self": "/users/seller-71460518",
          "items": "/users/seller-71460518/items",
          "card_accounts": "/users/seller-71460518/card_accounts",
          "paypal_accounts": "/users/seller-71460518/paypal_accounts",
          "bank_accounts": "/users/seller-71460518/bank_accounts",
          "wallet_accounts": "/users/seller-71460518/wallet_accounts"
        }
      },
      {
        "id": "buyer-71439598",
        "full_name": "Buyer",
        "first_name": "Buyer",
        "last_name": "",
        "created_at": "2020-05-06T01:38:19.116Z",
        "updated_at": "2020-05-06T02:03:25.941Z",
        "email": "[email protected]",
        "location": "N/A",
        "links": {
          "self": "/users/buyer-71439598",
          "items": "/users/buyer-71439598/items",
          "card_accounts": "/users/buyer-71439598/card_accounts",
          "paypal_accounts": "/users/buyer-71439598/paypal_accounts",
          "bank_accounts": "/users/buyer-71439598/bank_accounts",
          "wallet_accounts": "/users/buyer-71439598/wallet_accounts"
        }
      }
    ],
    "meta": {
      "limit": 2,
      "offset": 0,
      "total": 16
    },
    "links": {
      "self": "/users"
    }
  }
}

📌 Need Help?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.