Code Sample: Decrypting a Webhook Payload

The Webhook data payload is encrypted for security purposes, and it can be decrypted using accessToken below:

Javascript

NPM Package: https://www.npmjs.com/package/jsonwebtoken

Sample code

import jwt from "jsonwebtoken";

const webhookData = "eyJhbGciOiJIUzI1NiJ9.eyJ3ZWJob29rRGF0YSI6eyJpZCI6ImUxOTNkNGQ0LTYzOWUtNDYwYS04YmFmLWQyN2Y0YjY4Yjg4MSIsIndhbGxldEFkZHJlc3MiOiIweEQ5MDJkN2VCRjdiYzVlQ2E5RUVBMjJhNkVlOUYxQTMwRUJlQkVGZUUiLCJjcmVhdGVkQXQiOiIyMDI0LTA1LTA3VDExOjA5OjIwLjIxM1oiLCJzdGF0dXMiOiJBV0FJVElOR19QQVlNRU5UX0ZST01fVVNFUiIsImZpYXRDdXJyZW5jeSI6IkdCUCIsInVzZXJJZCI6IjcyNmQ5MTQ0LWRjOTctNDUxZS05YjkxLTk4ZWE0YzE0MGU1YyIsImNyeXB0b0N1cnJlbmN5IjoiRVRIIiwiaXNCdXlPclNlbGwiOiJCVVkiLCJmaWF0QW1vdW50Ijo1MywiaXBBZGRyZXNzIjoiMzUuMTc3LjE1OC45IiwiYW1vdW50UGFpZCI6MCwicGF5bWVudE9wdGlvbklkIjoiZ2JwX2JhbmtfdHJhbnNmZXIiLCJ3YWxsZXRMaW5rIjoiaHR0cHM6Ly9zZXBvbGlhLmV0aGVyc2Nhbi5pby9hZGRyZXNzLzB4RDkwMmQ3ZUJGN2JjNWVDYTlFRUEyMmE2RWU5RjFBMzBFQmVCRUZlRSIsInF1b3RlSWQiOiI4MDNhNzY2OS00YWNlLTRhNGYtYTM3My05Y2QzOWYwOGQzNzMiLCJvcmRlclByb2Nlc3NpbmdUeXBlIjoiTk9STUFMIiwiYWRkcmVzc0FkZGl0aW9uYWxEYXRhIjpmYWxzZSwibmV0d29yayI6ImV0aGVyZXVtIiwiY29udmVyc2lvblByaWNlIjowLjAwMDQwMjcxNTMwNTcwMzc1NywiY3J5cHRvQW1v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I6MCwiZ2FzQ29zdGluTG9jYWxDdXJyZW5jeUJ5RmlhdFBhcnRuZXIiOjAsImdhc0Nvc3RpbkxvY2FsQ3VycmVuY3lCeUNyeXB0b1BhcnRuZXIiOjAsInBhcnRuZXJGZWVEZWNpbWFsIjowLjAyLCJwYXJ0bmVyRmVlSW5Mb2NhbEN1cnJlbmN5IjoxLjA2LCJ0b3RhbEZlZURlY2ltYWwiOjAuMTA4ODY3OTI0NTI4MzAxODgsInRvdGFsRmVlQW1vdW50Ijo1Ljc3LCJnYXNDdXJyZW5jeSI6IkVUSCIsImdhc0luTmF0aXZlVG9rZW4iOjAuMDAxNSwiZ2FzQ3VycmVuY3lSYXRlSW5Vc2QiOjAuMDAwMzIyODMxNjIwNzExNTg1NDcsInRvdGFsQW1vdW50Q2hhcmdlZEJ5VHJhbnNhayI6NS43NjU2ODI1MzkyODUwMDF9fSwicGFydG5lckZlZUluTG9jYWxDdXJyZW5jeSI6MS4wNiwic3RhdHVzSGlzdG9yaWVzIjpbXX0sImV2ZW50SUQiOiJPUkRFUl9DUkVBVEVEIiwiY3JlYXRlZEF0IjoiMjAyNC0wNS0wN1QxMTowOToyMi4wOTFaIn0.W07qJG6jlyzid-JrnY7G4CsUOqk8wtcvfrdygGzt5N4";

const accessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBUElfS0VZIjoiZDc5NjcxYTQtYjAyMS00YTRmLWE0NDQtNjg2MmE2ODBhOTRiIiwiaWF0IjoxNzE1MDgxMzI1LCJleHAiOjE3MTU2ODYxMjV9.NJw7DRIpYZnT2N5pLDkGzd1jybIim_1VWtu930xba7s";
    
const decodedData = jwt.verify(webhookData, accessToken);

console.log(decodedData);

Java

dependencies {
    // Other dependencies...

    // JWT dependencies
    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
}
<dependencies>
        <!-- Other dependencies... -->
        
        <!-- JWT dependencies -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.11.5</version>
        </dependency>
</dependencies>

Sample code

package com.transak.webhookjavamaven;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import javax.crypto.SecretKey;

public class WebhookJavaMavenApplication {

    public static void main(String[] args) {
        String secret = "REFRESH_ACCESS_TOKEN";
        String jwt = "data field in the Webhook Response";

        // Decode the secret
        SecretKey key = Keys.hmacShaKeyFor(secret.getBytes());

        // Parse the JWT
        Claims claims = Jwts.parserBuilder()
                .setSigningKey(key)
                .build()
                .parseClaimsJws(jwt)
                .getBody();

        // Output the claims
        System.out.println("Claims: " + claims);
    }
}

Sample decrypted payload data

{
  "webhookData": {
    "id": "181b6159-2192-4f68-8647-f48e6e8f58c7",
    "walletAddress": "0xD902d7eBF7bc5eCa9EEA22a6Ee9F1A30EBeBEFeE",
    "createdAt": "2024-08-23T10:33:09.426Z",
    "status": "COMPLETED",
    "fiatCurrency": "EUR",
    "userId": "243a8ce2-9cc6-41a9-aaeb-b0deeb0b19a3",
    "cryptoCurrency": "ETH",
    "isBuyOrSell": "BUY",
    "fiatAmount": 32,
    "ipAddress": "35.177.158.9",
    "amountPaid": 32,
    "paymentOptionId": "sepa_bank_transfer",
    "walletLink": "https://sepolia.etherscan.io/address/0xD902d7eBF7bc5eCa9EEA22a6Ee9F1A30EBeBEFeE",
    "quoteId": "0b9edf4d-2de1-4f2e-bdb6-07bc61c380f5",
    "orderProcessingType": "NORMAL",
    "addressAdditionalData": false,
    "network": "ethereum",
    "conversionPrice": 0.00041416655266757863,
    "cryptoAmount": 0.01211023,
    "totalFeeInFiat": 2.76,
    "fiatAmountInUsd": 35.57,
    "countryCode": "IN",
    "stateCode": "Karnataka",
    "orderChannelType": "WIDGET",
    "userKycType": "STANDARD",
    "cardPaymentData": {
      "orderId": "181b6159-2192-4f68-8647-f48e6e8f58c7",
      "paymentId": "66c8656bb38a7908fadc77db",
      "pgData": {
        "paymentOptions": [
          {
            "currency": "EUR",
            "id": "sepa_bank_transfer",
            "name": "Bank Transfer Details",
            "fields": [
              {
                "name": "Bank Name",
                "value": "Transak Limited"
              },
              {
                "name": "IBAN",
                "value": "GB69MOCK00000003743944"
              },
              {
                "name": "Bank Name",
                "value": "Modulr"
              },
              {
                "name": "Bank Address",
                "value": "Scale Space, 58 Wood Lane, London, W12 7RZ"
              }
            ]
          }
        ],
        "liquidityProvider": "MODULR",
        "status": "CREATED"
      },
      "liquidityProvider": "MODULR",
      "updatedAt": "2024-08-23T10:33:58.753Z",
      "status": "CAPTURED",
      "processedOn": "2024-08-23T10:33:57.000Z"
    },
    "statusHistories": [
      {
        "status": "PENDING_DELIVERY_FROM_TRANSAK",
        "createdAt": "2024-08-23T10:33:59.408Z",
        "message": "*๐Ÿ’ธ Payment reconciled successfully. Received 32 EUR",
        "isEmailSentToUser": false,
        "partnerEventId": "ORDER_PROCESSING"
      }
    ],
    "isFirstOrder": false,
    "updatedAt": "2024-08-23T10:34:06.371Z",
    "completedAt": "2024-08-23T10:34:39.412Z",
    "transactionHash": "DUMMY_TX_ID",
    "transactionLink": "https://sepolia.etherscan.io/tx/DUMMY_TX_ID",
    "conversionPriceData": {
      "_id": "139474c7-99c5-4232-9a05-c6ccd6a973ed",
      "id": "139474c7-99c5-4232-9a05-c6ccd6a973ed",
      "createdAt": "2024-08-23T10:34:06.352Z",
      "fiatCurrency": "EUR",
      "cryptoCurrency": "ETH",
      "paymentMethod": "sepa_bank_transfer",
      "fiatAmount": 32,
      "network": "ethereum",
      "cryptoAmount": 0.01211023,
      "isBuyOrSell": "BUY",
      "conversionPrice": 0.00041416641727771563,
      "marketConversionPrice": 0.00041628949369556297,
      "slippage": 0.51,
      "cryptoLiquidityProvider": "transak",
      "fiatLiquidityProvider": "coinbase",
      "partnerApiKey": "d79671a4-b021-4a4f-a444-6862a680a94b",
      "sourceTokenAmount": 0.012110226041200406,
      "sourceToken": "ETH",
      "notes": [],
      "fiatFeeAmount": 2.76,
      "feeDecimal": 0.08625,
      "swaps": [
        {
          "sourceCurrency": "EUR",
          "destinationCurrency": "USDT",
          "sourceAmount": 32,
          "destinationAmount": 35.57563545494966,
          "paymentMethod": "sepa_bank_transfer",
          "liquidityProvider": "coinbase",
          "conversionPrice": 1.111738607967177,
          "feeInSourceAmount": 0,
          "networkFeeInSourceAmount": 0,
          "marketConversionPrice": 1.111738607967177,
          "isNonCustodial": false,
          "isFiatliquidityProvider": true,
          "isFiatPartnerDirectCryptoDeposit": false,
          "isFiatPartnerAccountWalletDeposit": false,
          "liquidityProviderData": false,
          "originalDestinationAmount": 35.57563545494966
        },
        {
          "sourceCurrency": "USDT",
          "destinationCurrency": "ETH",
          "sourceAmount": 35.57563545494966,
          "destinationAmount": 0.0132533253528869,
          "liquidityProvider": "transak",
          "conversionPrice": 0.0003725393849863884,
          "networkFeeInSourceAmount": 0,
          "networkFeeInDestinationAmount": 0,
          "marketConversionPrice": 0.0003725393849863884,
          "liquidityProviderData": false,
          "isNonCustodial": false
        },
        {
          "sourceCurrency": "ETH",
          "destinationCurrency": "ETH",
          "sourceAmount": 0.0132533253528869,
          "destinationAmount": 0.0132533253528869,
          "liquidityProvider": "transak",
          "conversionPrice": 1,
          "isCryptoliquidityProvider": true,
          "networkFeeInSourceAmount": 0.000067651170404,
          "networkFeeInDestinationAmount": 0.000067651170404,
          "marketConversionPrice": 1,
          "liquidityProviderData": false,
          "isFiatPartnerAccountWalletDeposit": false
        }
      ],
      "fees": [
        {
          "name": "Transak fee",
          "value": 2.6,
          "id": "transak_fee",
          "ids": [
            "transak_fee",
            "partner_fee"
          ]
        },
        {
          "name": "Network/Exchange fee",
          "value": 0.16,
          "id": "network_fee",
          "ids": [
            "network_fee"
          ]
        }
      ],
      "fiatAmountInUsd": 35.57,
      "internalFees": [
        {
          "name": "Network/Exchange fee",
          "id": "network_fee",
          "value": 0.16
        },
        {
          "name": "Transak fee",
          "id": "transak_fee",
          "value": 1
        },
        {
          "name": "Transak fee",
          "id": "partner_fee",
          "value": 1.6
        }
      ],
      "cost": {
        "ethPriceInLocalCurrency": 2402.17448469,
        "gasCostinLocalCurrency": 0.16334786495892,
        "transakMinimumFee": 1,
        "transakFeeAmount": 1,
        "fiatLiquidityProviderFee": 0,
        "gasCostinLocalCurrencyByFiatPartner": 0,
        "gasCostinLocalCurrencyByCryptoPartner": 0,
        "partnerFeeDecimal": 0.05,
        "partnerFeeInLocalCurrency": 1.6,
        "totalFeeDecimal": 0.08625,
        "totalFeeAmount": 2.76,
        "gasCurrency": "ETH",
        "gasInNativeToken": 0.000068,
        "gasCurrencyRateInUsd": 0.0003744603090795391,
        "totalAmountChargedByTransak": 2.76334786495892
      }
    },
    "partnerFeeInLocalCurrency": 1.6
  },
  "eventID": "ORDER_COMPLETED",
  "createdAt": "2024-08-23T10:34:40.070Z"
}