Subscribe to P2P large amount payment account changes

# Subscribe to P2P large amount payment account changes

This interface is provided by merchants that connect to P2P business. If the switch for subscribing to large-value bank card payment changes is turned on, the platform will request this interface when there is a change in the large-value bank card payment account. When receiving an HTTP request, please respond with httpcode=200 (HTTP response status code), otherwise the notification will be sent 16 times within 5 hours.

# Notification Parameters

Parameter Type Required Description Example
id string Y Bank card unique ID 10
bankName string Y Bank Name State Bank of India
accountNumber string Y Bank card number 41459877630
name string Y Payee Name Sachin Pujeri
ifscCode string Y IFSC SBIN0000899
branchName string Y Branch Name sagar Bank
status int Y Current status of bank card
0-online
1-offline
2-deleted
0
operationType int Y Operation type
0-Add
1-Edit
2-Go online
3-Go offline
4-Delete
0
operationTime long Y Trigger time (timestamp: milliseconds) 1705128180000
sign string Y sign EcCs7GlN1UzEAflgpyJ4lKIHe9+lS/gdkcEvWI
+nSlcvvz1c+Dg4Zi8sFmpYaoOMGxS3/BY66F
Gq2TXzVGhAciq2kFmwZFtYbFvr7xPTaNf/n0R
u7ZtV/jo3uBnfc9/JI6XlEWlIbPtGsVpH7CLhzgh
dqIT+YbPEdhX2ZKETFTTfIj6PzctY9eOsZ51Yb
HYnXv0jTWn1hdPoDofAF9RmoNaXK4FGYibQ
BSvVA6w4rM6hCXlbTeHdMc4askrZlrHeG3uhyD
34VlXs74cdzAZ+oROMXBcgXR4ObsJVDFz9tsJ
H92iaxlKTF0lEFZa/To5ezLpHvTOAK0uY/K6IxvO
AAg==

# Asynchronous Notification Message Example

{
  "id":"25",
  "bankName":"State Bank of India",
  "accountNumber":"41459877630",
  "name":"Sachin Pujeri",
  "ifscCode":"SBIN0000899",
  "branchName":"sagar Bank",
  "status":0,
  "operationType":0,
  "operationTime":1705128180000,
  "sign":"EcCs7GlN1UzEAflgpyJ4lKIHe9+lS/gdkcEvWI+nSlcvvz1c+Dg4Zi8sFmpYaoOMGxS3/BY66FGq2TXzVGhAciq2kFmwZFtYbFvr7xPTaNf/n0Ru7ZtV/jo3uBnfc9/JI6XlEWlIbPtGsVpH7CLhzghdqIT+YbPEdhX2ZKETFTTfIj6PzctY9eOsZ51YbHYnXv0jTWn1hdPoDofAF9RmoNaXK4FGYibQBSvVA6w4rM6hCXlbTeHdMc4askrZlrHeG3uhyD34VlXs74cdzAZ+oROMXBcgXR4ObsJVDFz9tsJH92iaxlKTF0lEFZa/To5ezLpHvTOAK0uY/K6IxvOAAg=="
}

# Asynchronous Notification Code Implementation Demo

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("callback")
public class TestCallbackController {

    /**
     * Platform public key
     */
    public static String PLATFORM_PUB_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1dad35S74jfLPbHJh8P0jDHiTvkxwrtITK97ovVu19B24UdiHyHoEZgtNlS6alFQj1ULQ71d6EPh2rWCNkS2b5HGQXwDYBtwvesVQ8h4Sf3eVPTTLGw3BS7Os4vtDEN6BezMdv3sUG2N5i6JF+5H4CQTq3MD2Cx6u/Cv7oFOdFqeDT0AH+TR7uyZxn69OtkJaHHr834EUcdShJKKMQtbC11WCcut7ilDUgdvZnThiVTq7cfl8mcC9FDKcQ9bMWamScWIB5cJQdUW23Kr0c1NvZlpgPS8U5VODM4Uc4muHJPD2cJmquuJ+4AGP36rEk27lUB3h7B6JI1QGiuh1yyPDwIDAQAB";

    /**
     * P2P large amount receiving account change callback
     * @param paramMap
     * @param response
     */
    @PostMapping("payIn")
    public void payInCallback(@RequestBody Map<String, Object> paramMap, HttpServletResponse response) throws Exception{
        boolean verifyResult = CheeseTradeRSAUtil.verifySign(paramMap, PLATFORM_PUB_KEY);
        if (verifyResult) {
            //Signature verification successful
            //Order notification business processing logic
            String name = (String)paramMap.get("name");
            String branchName = (String)paramMap.get("branchName");
            String bankName = (String)paramMap.get("bankName");
            Integer operationType = (Integer)paramMap.get("operationType");
            String id = (String)paramMap.get("id");
            String accountNumber = (String)paramMap.get("accountNumber");
            String ifscCode = (String)paramMap.get("ifscCode");
            Integer status = (Integer)paramMap.get("status");
            Long gmtEnd = (Long)paramMap.get("operationTime");
        } else {
            //Signature verification failed
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        }
    }

}
<?php
//This code has been verified in PHP5.6 version
class TestCallbackController 
{

    /**
     * Platform public key
     */
    const PLATFORM_PUB_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1dad35S74jfLPbHJh8P0jDHiTvkxwrtITK97ovVu19B24UdiHyHoEZgtNlS6alFQj1ULQ71d6EPh2rWCNkS2b5HGQXwDYBtwvesVQ8h4Sf3eVPTTLGw3BS7Os4vtDEN6BezMdv3sUG2N5i6JF+5H4CQTq3MD2Cx6u/Cv7oFOdFqeDT0AH+TR7uyZxn69OtkJaHHr834EUcdShJKKMQtbC11WCcut7ilDUgdvZnThiVTq7cfl8mcC9FDKcQ9bMWamScWIB5cJQdUW23Kr0c1NvZlpgPS8U5VODM4Uc4muHJPD2cJmquuJ+4AGP36rEk27lUB3h7B6JI1QGiuh1yyPDwIDAQAB";

    /**
     * P2P large amount receiving account change callback
     * @param paramMap
     * @param response
     */
    public function payInCallback($paramMap, $response) {
        $sign = $paramMap['sign'];
        unset($result['sign']);
        $string = ConnectStrings($paramMap);
        $verifyResult = verifySign($string, $sign,self::PLATFORM_PUB_KEY);
        if ($verifyResult) {
            //Signature verification successful
            //Order notification business processing logic
            $name = $paramMap["name"];
            $branchName = $paramMap["branchName"];
            $bankName = $paramMap["bankName"];
            $operationType = $paramMap["operationType"];
            $id = $paramMap["id"];
            $accountNumber = $paramMap["accountNumber"];
            $ifscCode = $paramMap["ifscCode"];
            $status = $paramMap["status"];
            $operationTime = $paramMap["operationTime"];
        } else {
            //Signature verification failed
            http_response_code(400);
        }
    }

}

//Concatenating strings
 function ConnectStrings($params)
{
    // Get all the keys of the map and sort them
    $keys = array_keys($params);
    sort($keys);

    // Traverse the key list, get the corresponding value, and concatenate it into a string
    $str = '';

    foreach ($keys as $key) {
        $str .=  $key . '=' . $params[$key] . '&';
    }
    $str = rtrim($str, '&');
    return $str;
}  

//Verify signature
function verifySign($data, $sign, $pubKey){
    $sign = base64_decode($sign);
    $key = openssl_pkey_get_public($pubKey);
    $result = openssl_verify($data, $sign, $key, OPENSSL_ALGO_SHA256) === 1;
    return $result;
}

?>

const express = require('express');
const bodyParser = require('body-parser');
//The functions of the introduced signature tool class (CheeseTradeRSAUtil). 
//The signature tool class can refer to the DEMO in "Signature & Verification Algorithm"
const  {verifySign}= require('./CheeseTradeRSAUtil');

const app = express();
//Parsing JSON request body
app.use(bodyParser.json());

// Platform public key
const platPublicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1dad35S74jfLPbHJh8P0jDHiTvkxwrtITK97ovVu19B24UdiHyHoEZgtNlS6alFQj1ULQ71d6EPh2rWCNkS2b5HGQXwDYBtwvesVQ8h4Sf3eVPTTLGw3BS7Os4vtDEN6BezMdv3sUG2N5i6JF+5H4CQTq3MD2Cx6u/Cv7oFOdFqeDT0AH+TR7uyZxn69OtkJaHHr834EUcdShJKKMQtbC11WCcut7ilDUgdvZnThiVTq7cfl8mcC9FDKcQ9bMWamScWIB5cJQdUW23Kr0c1NvZlpgPS8U5VODM4Uc4muHJPD2cJmquuJ+4AGP36rEk27lUB3h7B6JI1QGiuh1yyPDwIDAQAB
-----END PUBLIC KEY-----`;

// callback interface
app.post('/callback/P2P', (req, res) => {
    const paramMap = req.body; // Get the parameters in the request body

    try {
        const verifyResult = verifySign(paramMap,platPublicKey);
        if (verifyResult) {
            // Signature verification successful
            const name  = paramMap.name ;
            const branchName = paramMap.branchName;
            const bankName = paramMap.bankName;
            const operationType = paramMap.operationType;
            const id = paramMap.id;
            const accountNumber = paramMap.accountNumber;
            const ifscCode = paramMap.ifscCode;
            const status = paramMap.status;
            const operationTime = paramMap.operationTime;

            // Order notification business processing logic
            console.log('Signature verification successful, order processed:', {
                name,
                branchName,
                bankName,
                operationType,
                id,
                accountNumber,
                ifscCode,
                status,
                operationTime,
            });

            // Return a successful response
            res.status(200).json({ message: 'Successful processing' });
        } else {
            // Signature verification failed
            res.status(400).json({ message: 'Signature verification failed' });
        }
    } catch (error) {
        // Handling Exceptions
        console.error('An error occurred while processing the callback:', error);
        res.status(500).json({ message: 'Internal server error' });
    }
});