Aller au contenu principal

Écouter les Webhooks

Configuration des Webhooks

Pour configurer les webhooks

  1. Allez sur la page Webhooks.

  2. Cliquez sur le bouton Modifier. webhook_action edit

  3. Envisagez d'ajouter uniquement une URL https pour un taux de succès plus élevé. webhook_action url

  4. Cliquez sur Enregistrer.

webhook_click on save

Pour modifier le nombre de demandes pouvant être reçues par le webhook :

  1. Cliquez sur le bouton Modifier à côté du taux. webhook_edit rate

  2. Entrez le nombre souhaité de demandes par minute. webhook_save the rate

  3. Cliquez sur Enregistrer.

Guide Webhook

Le webhook doit accepter le corps de la requête sous forme de chaîne. Cette chaîne doit être encodée en Base64 et chiffrée à l'aide de la clé de chiffrement spécifiée sur la page des clés. keys_copy the encryption key

Procédure de chiffrement

  • Méthode de chiffrement :
String(
Base64.getDecoder().decode(
decryptWithPassword(
request,
"encryptionKey"
)
)
)

You can find the API key here. keys_copy the api key

Après avoir déchiffré la requête avec succès, convertissez-la en un objet JSON avec la structure suivante :

{
"transactionCode": "",
"state": "",
"paymentInstrument": "",
"paymentSubInstrument": "",
"currency": {
"code": "",
"name": "",
"knownName": "",
"serviceable": false,
"notServiceableMessage": "",
"decimalPrecision": 0,
"id": "",
"lastUpdated": null,
"createdDate": null,
"dataStatus": ""
},
"amount": 0.0,
"cancelReason": null,
"comment": "",
"extraCustomerInfo": ""
}

Pour envoyer le transactionCode dans le JSON fourni après l'avoir chiffré :

  1. Chiffrez le transactionCode :

    encrypt(
    Base64.getEncoder().encodeToString(payload.transactionCode.encodeToByteArray()),
    "encryptionKey"
    )
  2. Enveloppez la chaîne chiffrée dans un format JSON :

    {
    "response": "encrypted string"
    }
  3. Retournez-le avec le code de réponse HTTPStatusCode 200.

Exemple de contrôleur Webhook :

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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 org.springframework.stereotype.Component;
import java.util.*;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;

@RestController
@RequestMapping("/paymentProvider/webhook/change/webhook")
class CustomController {

@PostMapping
fun customWebHookResponse(
@RequestBody request: String
): ResponseEntity<OutgoingWebHookResponse> {
val payload = ConverterStringToObjectList.getSingleObject<OutGoingWebHookPayload>(
decode(
decryptWithPassword(
request,
"encryptionKey"
)
)
);
return ResponseEntity(
OutgoingWebHookResponse(
encrypt(
encode(payload.transactionCode),
"encryptionKey"
)
), HttpStatus.OK
);
}

fun encrypt(
stringToEncrypt: String,
password: String,
): String {
try {
val salt = "your api key";
val ivParameterSpec: IvParameterSpec = AESUtil.generateIv();
val key: SecretKey = AESUtil.getKeyFromPassword(password, salt);
return AESUtil.encryptPasswordBased(stringToEncrypt, key, ivParameterSpec);
} catch (ex: Exception) {
throw ex;
}
}

fun decryptWithPassword(
toDecrypt: String,
password: String
): String {
return try {
val saltFinal = "your api key";
val ivParameterSpec: IvParameterSpec = AESUtil.generateIv();
val key: SecretKey = AESUtil.getKeyFromPassword(password, saltFinal);
AESUtil.decryptPasswordBased(toDecrypt, key, ivParameterSpec);
} catch (ex: Exception) {
throw ex;
}
}

fun encode(toEncode: String): String {
return Base64.getEncoder().encodeToString(toEncode.encodeToByteArray());
}

fun decode(toDecode: String): String {
return String(Base64.getDecoder().decode(toDecode));
}
}

Exemple de modèle de réponse :

data class OutgoingWebHookResponse(
val response: String = "",
)

Exemple de modèle de requête :

data class OutGoingWebHookPayload(
var transactionCode: String = "",
var state: String = "",
var paymentInstrument: String = "",
var paymentSubInstrument: String ?= null,
var currency: Currency = Currency(),
var amount: BigDecimal = BigDecimal.ZERO,
var cancelReason: String ?= null,
var comment: String = "",
var extraCustomerInfo: String = "",
)
data class Currency(
var code: String = "",
var name: String = "",
var knownName: String = "",
var serviceable: Boolean = false,
var notServiceableMessage: String? = "",
var decimalPrecision: Int = 0,
var id: String = "",
var lastUpdated: ZonedDateTime = ZonedDateTime.now(),
var createdDate: ZonedDateTime = ZonedDateTime.now(),
var dataStatus: String = "",
)

Encryption/Decryption in Other Languages

Chiffrement/Déchiffrement dans d'autres langages

Effacer les Webhooks en attente.

  1. Allez dans la section Commerçants.
  2. Accédez à la page Détails du commerçant.
  3. Cliquez sur le bouton Effacer là où la flèche rouge pointe.

clear_merchant_pending_webhooks

Voir les appels de Webhooks en attente

Pour voir les webhooks en attente pour un commerçant :

  1. Allez dans la section Commerçants.
  2. Accédez à la page Détails du commerçant.
  3. Vérifiez le nombre de Webhooks en attente du commerçant, qui est mis en surbrillance dans la boîte rouge.

merchant_pending_webhooks