### Calculate Signature for vads_ Fields in Java Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java This Java function calculates a signature based on request parameters starting with 'vads_'. It retrieves, sorts, and concatenates these parameters along with a separator and a secret key, then encodes the resulting string using SHA. Dependencies include HttpServletRequest, HttpServletResponse, ActionMapping, BasicForm, SortedSet, TreeSet, Enumeration, and a Sha utility class. ```java public ActionForward performCheck(ActionMapping actionMapping, BasicForm form, HttpServletRequest request, HttpServletResponse response){ SortedSet vadsFields = new TreeSet(); Enumeration paramNames = request.getParameterNames(); // Recupere et trie les noms des champs vads_* par ordre alphabetique while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); if (paramName.startsWith( "vads_" )) { vadsFields.add(paramName); } } // Calcule la signature String sep = Sha.SEPARATOR; StringBuilder sb = new StringBuilder(); for (String vadsParamName : vadsFields) { String vadsParamValue = request.getParameter(vadsParamName); if (vadsParamValue != null) { sb.append(vadsParamValue); } sb.append(sep); } sb.append( shaKey ); String c_sign = Sha.encode(sb.toString()); return c_sign; } ``` -------------------------------- ### Exemple d'implémentation de calcul de signature en PHP Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java Fournit un exemple d'implémentation PHP pour calculer la signature requise lors de l'utilisation de l'API de paiement. Ce code assure la sécurité et l'intégrité des données transmises. ```php ``` -------------------------------- ### Exemple d'implémentation de calcul de signature en Java Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java Fournit un exemple d'implémentation Java pour calculer la signature nécessaire à l'interaction avec la plateforme de paiement. Ce code est essentiel pour sécuriser les transactions. ```java /* * Exemple d'implémentation pour le calcul de signature en Java * Ce code est un placeholder et doit être adapté aux spécificités de l'API. */ public class SignatureCalculator { public static String calculateSignature(String data, String secretKey) { // Logique de calcul de signature (par exemple, HMAC-SHA256) // Ceci est une implémentation fictive String signature = data + secretKey; return signature; } public static void main(String[] args) { String transactionData = "amount=100¤cy=EUR&order_id=12345"; String merchantSecretKey = "YOUR_SECRET_KEY"; String calculatedSignature = calculateSignature(transactionData, merchantSecretKey); System.out.println("Calculated Signature: " + calculatedSignature); } } ``` -------------------------------- ### API REST - Create Subscription Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java Details on how to create a recurring payment subscription using the API. ```APIDOC ## POST /api/subscriptions ### Description Creates a new subscription for recurring payments. ### Method POST ### Endpoint /api/subscriptions ### Parameters #### Request Body - **customer_id** (string) - Required - The identifier for the customer. - **plan_id** (string) - Required - The identifier for the subscription plan. - **payment_token** (string) - Required - A token representing the customer's payment method. - **start_date** (string) - Optional - The date the subscription should start (YYYY-MM-DD). ### Request Example ```json { "customer_id": "CUST67890", "plan_id": "PLAN_PREMIUM", "payment_token": "tok_abcdef123" } ``` ### Response #### Success Response (201 Created) - **subscription_id** (string) - The unique identifier for the created subscription. - **status** (string) - The status of the subscription (e.g., ACTIVE, TRIAL). #### Response Example ```json { "subscription_id": "sub_xyz789", "status": "ACTIVE" } ``` ``` -------------------------------- ### API REST - Create Payment Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java This section details how to create a payment using the REST API. It covers the necessary request parameters and response structure for a successful payment creation. ```APIDOC ## POST /api/payments ### Description Creates a new payment transaction. ### Method POST ### Endpoint /api/payments ### Parameters #### Request Body - **amount** (integer) - Required - The amount to be paid. - **currency** (string) - Required - The currency of the payment (e.g., EUR, USD). - **order_id** (string) - Required - A unique identifier for the order. - **customer_id** (string) - Optional - Identifier for the customer. - **payment_method** (string) - Optional - The desired payment method. ### Request Example ```json { "amount": 10000, "currency": "EUR", "order_id": "ORD12345", "customer_id": "CUST67890", "payment_method": "credit_card" } ``` ### Response #### Success Response (201 Created) - **payment_id** (string) - The unique identifier for the created payment. - **status** (string) - The status of the payment (e.g., PENDING, SUCCESSFUL). - **redirect_url** (string) - The URL to redirect the user for payment processing. #### Response Example ```json { "payment_id": "pay_abc123", "status": "PENDING", "redirect_url": "https://payment.example.com/pay?token=xyz789" } ``` ``` -------------------------------- ### Calculer la signature en JAVA Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/sitemap Exemple d'implémentation en Java pour calculer la signature lors de l'intégration avec l'API Formulaire PayZen. Nécessite des connaissances en cryptographie et en gestion des clés. ```java public static String generateSignature(Map params, String privateKey) throws Exception { // Convertir les paramètres en une chaîne triée par clé StringBuilder data = new StringBuilder(); List keys = new ArrayList<>(params.keySet()); Collections.sort(keys); for (String key : keys) { data.append(params.get(key)); } // Calculer le HMAC-SHA256 Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKey = new SecretKeySpec(privateKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256"); sha256_HMAC.init(secretKey); // Encoder le résultat en Base64 return Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(data.toString().getBytes(StandardCharsets.UTF_8))); } ``` -------------------------------- ### POST /payment/form Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/sitemap Submit a payment form via POST request. This endpoint is used to initiate a payment transaction. ```APIDOC ## POST /payment/form ### Description Submits a payment form via POST request to initiate a payment transaction. ### Method POST ### Endpoint /payment/form ### Parameters #### Request Body - **signature** (string) - Required - The signature calculated for the payment request. - **amount** (integer) - Required - The amount of the payment in the smallest currency unit (e.g., cents). - **currency** (string) - Required - The currency code (e.g., EUR, USD). - **order_id** (string) - Required - A unique identifier for the order. - **customer_id** (string) - Optional - Identifier for the customer. - **return_url** (string) - Optional - The URL to redirect the customer to after payment. - **notification_url** (string) - Optional - The URL to send payment notifications to. ### Request Example ```json { "signature": "a1b2c3d4e5f6...", "amount": 1000, "currency": "EUR", "order_id": "ORDER12345", "customer_id": "CUST987", "return_url": "https://yourshop.com/return", "notification_url": "https://yourshop.com/notify" } ``` ### Response #### Success Response (200) - **redirect_url** (string) - The URL to redirect the user to for payment completion. #### Response Example ```json { "redirect_url": "https://payzen.example.com/payment/page?token=..." } ``` ``` -------------------------------- ### Calculer la signature en PHP Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/sitemap Exemple d'implémentation en PHP pour calculer la signature lors de l'intégration avec l'API Formulaire PayZen. Utilise la fonction hash avec l'algorithme HmacSHA256. ```php ``` -------------------------------- ### API REST - Handle Payment Notifications (IPN) Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java This section explains how to implement the Instant Payment Notification (IPN) to receive real-time updates on payment status changes. ```APIDOC ## POST /ipn/handle ### Description Receives and processes Instant Payment Notifications (IPN) from the payment platform. ### Method POST ### Endpoint /ipn/handle ### Parameters #### Request Body - **transaction_id** (string) - Required - The ID of the transaction. - **status** (string) - Required - The new status of the transaction (e.g., PAID, FAILED, REFUNDED). - **custom_data** (object) - Optional - Any custom data sent with the payment. - **signature** (string) - Required - A signature to verify the authenticity of the notification. ### Request Example ```json { "transaction_id": "pay_abc123", "status": "PAID", "custom_data": { "order_ref": "ORD12345" }, "signature": "a1b2c3d4e5f6..." } ``` ### Response #### Success Response (200 OK) - **message** (string) - Confirmation message (e.g., "Notification processed successfully"). #### Response Example ```json { "message": "Notification processed successfully" } ``` ``` -------------------------------- ### POST /ipn/handle Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/sitemap Handle Instant Payment Notification (IPN) data. This endpoint receives real-time updates about payment status. ```APIDOC ## POST /ipn/handle ### Description Handles Instant Payment Notification (IPN) data sent by the payment platform. This endpoint is used to receive real-time updates on payment status. ### Method POST ### Endpoint /ipn/handle ### Parameters #### Request Body - **payment_status** (string) - Required - The status of the payment (e.g., SUCCESS, FAILED, PENDING). - **order_id** (string) - Required - The unique identifier for the order. - **transaction_id** (string) - Required - The unique identifier for the transaction. - **signature** (string) - Required - The signature to verify the IPN request. - **amount_received** (integer) - Optional - The amount received in the smallest currency unit. - **currency** (string) - Optional - The currency code. ### Request Example ```json { "payment_status": "SUCCESS", "order_id": "ORDER12345", "transaction_id": "TXN789012", "signature": "f0e9d8c7b6a5...", "amount_received": 1000, "currency": "EUR" } ``` ### Response #### Success Response (200) - **status** (string) - Acknowledgment status (e.g., "OK", "RECEIVED"). #### Response Example ```json { "status": "OK" } ``` ``` -------------------------------- ### API REST - Manage Transactions Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java Endpoints for managing transactions, such as issuing refunds. ```APIDOC ## POST /api/transactions/{transaction_id}/refund ### Description Issues a refund for a specific transaction. ### Method POST ### Endpoint /api/transactions/{transaction_id}/refund ### Parameters #### Path Parameters - **transaction_id** (string) - Required - The ID of the transaction to refund. #### Request Body - **amount** (integer) - Optional - The amount to refund. If not provided, the full amount is refunded. - **reason** (string) - Optional - The reason for the refund. ### Request Example ```json { "amount": 5000, "reason": "Customer request" } ``` ### Response #### Success Response (200 OK) - **refund_id** (string) - The unique identifier for the refund. - **status** (string) - The status of the refund (e.g., PROCESSING, COMPLETED). #### Response Example ```json { "refund_id": "ref_lmn456", "status": "COMPLETED" } ``` ``` -------------------------------- ### API REST - Manage Subscriptions Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java Endpoints for managing existing subscriptions, such as updating or canceling them. ```APIDOC ## PUT /api/subscriptions/{subscription_id} ### Description Updates an existing subscription. ### Method PUT ### Endpoint /api/subscriptions/{subscription_id} ### Parameters #### Path Parameters - **subscription_id** (string) - Required - The ID of the subscription to update. #### Request Body - **new_plan_id** (string) - Optional - The new plan to switch to. - **cancel_at_period_end** (boolean) - Optional - Set to true to cancel the subscription at the end of the current period. ### Request Example ```json { "new_plan_id": "PLAN_PRO", "cancel_at_period_end": true } ``` ### Response #### Success Response (200 OK) - **subscription_id** (string) - The identifier of the updated subscription. - **status** (string) - The updated status of the subscription. #### Response Example ```json { "subscription_id": "sub_xyz789", "status": "CANCELLED" } ``` ## DELETE /api/subscriptions/{subscription_id} ### Description Cancels a subscription immediately. ### Method DELETE ### Endpoint /api/subscriptions/{subscription_id} ### Parameters #### Path Parameters - **subscription_id** (string) - Required - The ID of the subscription to cancel. ### Response #### Success Response (200 OK) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Subscription cancelled successfully." } ``` ``` -------------------------------- ### POST /signature/calculate Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/sitemap Calculate the signature for a payment request. This is a crucial step for securing payment transactions. ```APIDOC ## POST /signature/calculate ### Description Calculates the signature required for securing payment requests. This is used to verify the integrity of the payment data. ### Method POST ### Endpoint /signature/calculate ### Parameters #### Request Body - **data** (object) - Required - The data object containing the parameters for which the signature needs to be calculated. - **amount** (integer) - Required - The amount of the payment. - **currency** (string) - Required - The currency code. - **order_id** (string) - Required - The unique order identifier. - **timestamp** (integer) - Required - The Unix timestamp of the request. - **merchant_id** (string) - Required - Your merchant ID. - **secret_key** (string) - Required - Your secret API key. ### Request Example ```json { "data": { "amount": 1000, "currency": "EUR", "order_id": "ORDER12345", "timestamp": 1678886400, "merchant_id": "MERCHANT_ABC", "secret_key": "YOUR_SECRET_KEY" } } ``` ### Response #### Success Response (200) - **signature** (string) - The calculated signature. #### Response Example ```json { "signature": "a1b2c3d4e5f6..." } ``` ``` -------------------------------- ### Build HMAC-SHA-256 Signature in Java Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java This Java code defines a class VadsSignatureExample with methods to build a signature using the HMAC-SHA-256 algorithm. It takes a TreeMap of parameters and a secret key as input. The signature is generated by concatenating parameter values with the secret key and then hashing the message using HMAC-SHA-256. Dependencies include Java's `javax.crypto` and `java.security` packages. Input is a TreeMap of String to String and a secret key String. Output is a Base64 encoded signature String. ```java import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Base64; import java.util.TreeMap; public class VadsSignatureExample { /** * Build signature (HMAC SHA-256 version) from provided parameters and secret key. * Parameters are provided as a TreeMap (with sorted keys). */ public static String buildSignature(TreeMap formParameters, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException { // Build message from parameters String message = String.join("+", formParameters.values()); message += "+" + secretKey; // Sign return hmacSha256Base64(message, secretKey); } /** * Actual signing operation. */ public static String hmacSha256Base64(String message, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException { // Prepare hmac sha256 cipher algorithm with provided secretKey Mac hmacSha256; try { hmacSha256 = Mac.getInstance("HmacSHA256"); } catch (NoSuchAlgorithmException nsae) { hmacSha256 = Mac.getInstance("HMAC-SHA-256"); } SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256"); hmacSha256.init(secretKeySpec); // Build and return signature return Base64.getEncoder().encodeToString(hmacSha256.doFinal(message.getBytes("UTF-8"))); } } ``` -------------------------------- ### Calculer la signature IPN en PHP (HMAC-SHA-256) Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/calculer-la-signature-de-l-ipn Cette fonction PHP calcule la signature IPN en triant les champs commençant par 'vads_', en les concaténant avec un '+', en ajoutant la clé de paiement, puis en appliquant l'algorithme HMAC-SHA-256 et l'encodage Base64. Elle prend en entrée un tableau de paramètres et la clé de paiement. ```php function getSignature ($params,$key) { /** * Fonction qui calcule la signature. * $params : tableau contenant les champs reçus dans l'IPN. * $key : clé de TEST ou de PRODUCTION */ //Initialisation de la variable qui contiendra la chaine à chiffrer $contenu_signature = ""; //Tri des champs par ordre alphabétique ksort($params); foreach($params as $nom=>$valeur){ //Récupération des champs vads_ if (substr($nom,0,5)=='vads_'){ //Concaténation avec le séparateur "+" $contenu_signature .= $valeur."+ "; } } //Ajout de la clé en fin de chaine $contenu_signature .= $key; //Encodage base64 de la chaine chiffrée avec l'algorithme HMAC-SHA-256 $sign = base64_encode(hash_hmac('sha256',$contenu_signature, $key, true)); return $sign; } ``` -------------------------------- ### Calculate SHA-1 Signature in Java Source: https://secure.osb.pf/doc/fr-FR/form-payment/quick-start-guide/exemple-d-implementation-en-java This Java code defines a utility class 'Sha' to calculate signatures using the SHA-1 algorithm. The `encode` method takes a source string, converts it to bytes using UTF-8 encoding, and then computes the SHA-1 hash. The resulting byte array is converted to a hexadecimal string representation. This snippet relies on Java's `java.security.MessageDigest`. Input is a String, and the output is a hexadecimal String representing the SHA-1 hash. ```java import java.security.MessageDigest; import java.security.SecureRandom; public class Sha { static public final String SEPARATOR = "+" ; public static String encode(String src) { try { MessageDigest md; md = MessageDigest.getInstance( "SHA-1" ); byte bytes[] = src.getBytes( "UTF-8" ); md.update(bytes, 0, bytes. length ); byte[] sha1hash = md.digest(); return convertToHex(sha1hash); } catch(Exception e){ throw new RuntimeException(e); } } private static String convertToHex(byte[] sha1hash) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < sha1hash. length ; i++) { byte c = sha1hash[i]; addHex(builder, (c >> 4) & 0xf); addHex(builder, c & 0xf); } return builder.toString(); } private static void addHex(StringBuilder builder, int c) { if (c < 10) builder.append((char) (c + '0' )); else builder.append((char) (c + 'a' - 10)); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.