Écouter les Webhooks
Configuration des Webhooks
Pour configurer les webhooks
-
Allez sur la page Webhooks.
-
Cliquez sur le bouton Modifier.
-
Envisagez d'ajouter uniquement une URL https pour un taux de succès plus élevé.
-
Cliquez sur Enregistrer.
Pour modifier le nombre de demandes pouvant être reçues par le webhook :
-
Cliquez sur le bouton Modifier à côté du taux.
-
Entrez le nombre souhaité de demandes par minute.
-
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.
Procédure de chiffrement
- Méthode de chiffrement :
String(
Base64.getDecoder().decode(
decryptWithPassword(
request,
"encryptionKey"
)
)
)
You can find the API key here.
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é :
-
Chiffrez le transactionCode :
encrypt(
Base64.getEncoder().encodeToString(payload.transactionCode.encodeToByteArray()),
"encryptionKey"
) -
Enveloppez la chaîne chiffrée dans un format JSON :
{
"response": "encrypted string"
} -
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.
- Allez dans la section Commerçants.
- Accédez à la page Détails du commerçant.
- Cliquez sur le bouton Effacer là où la flèche rouge pointe.
Voir les appels de Webhooks en attente
Pour voir les webhooks en attente pour un commerçant :
- Allez dans la section Commerçants.
- Accédez à la page Détails du commerçant.
- Vérifiez le nombre de Webhooks en attente du commerçant, qui est mis en surbrillance dans la boîte rouge.