Voucher Payments (Offline)

This page describes how to collect ZAR payments offline using Vouchers

Rave allows you to collect payments from your customers offline using vouchers. With voucher payments, your customer redeems (funds their wallet to get an equivalent value in voucher code) a voucher from Flash agent locations across south Africa and they can use the voucher on Flutterwave.

This section shows you how to accept payments using the Voucher method.

Pre-requisite for accepting Voucher payments.

  1. Sign-up for a rave account here (if you haven't already).

  2. Set up a webhook to get notified on payments, to see more on webhooks visit the webhook section.

  3. Setup your payment UI and instructions to properly guide your user through this payment method.

Testing Credentials

voucher - 1020822108705120
phone - 271000010010

Charge Step 1: Encrypt your payload.

{
"PBFPubKey": "FLWPUBK-4e581ebf8372cd691203b27227e2e3b8-X",
"currency": "ZAR",
"country": "ZA",
"amount": "100",
"pin": "19203804939000",
"email": "[email protected]",
"phonenumber": "0902620185",
"firstname": "temi",
"lastname": "desola",
"IP": "355426087298442",
"is_flash_voucher": 1,
"txRef": "MC-" + Date.now(),// your unique merchant reference
"meta": [{metaname: "flightID", metavalue: "123949494DC"}],
"device_fingerprint": "69e6b7f0b72037aa8428b70fbe03986c"
}

Parameter Definition

ParameterRequiredDescription
PBFPubKeyTrueThis is a unique key generated for each button created on Rave’s dashboard. It starts with a prefix FLWPUBK and ends with suffix X.
currencyTrue
(expected value: ZAR)
This is the specified currency to charge in.
countrytrue
(Expected value: ZA)
This is the pair country for the transaction with respect to the currency. See a list of Multicurrency support here Multicurrency Payments ]
pintrueThis is the voucher pin given to the user after redemption at the agent location. They would provide this to you as the voucher code.
amountTrueThis is the amount to be charged it is passed as - (“amount”:"100"). N.B. Amount should not be less than 100.
emailTrueThis is the email address of the customer.
phonenumberTrueThis is the phone number of the customer.
firstnameFalseThis is the first name of the card holder or the customer.
lastnameFalseThis is the last name of the card holder or the customer.
IPFalseIP - Internet Protocol. This represents the current IP address of the customer carrying out the transaction.
txRefTrueThis is a unique reference, unique to the particular transaction being carried out. It is generated by the merchant for every transaction.
is_flash_voucherTrue

(expected value: 1)
This identifies that a voucher transaction is being completed.
device_fingerprintFalseThis is the fingerprint for the device being used. It can be generated using a library on whatever platform is being used.

Sample encryption

<?php

function getKey($seckey){
  $hashedkey = md5($seckey);
  $hashedkeylast12 = substr($hashedkey, -12);

  $seckeyadjusted = str_replace("FLWSECK-", "", $seckey);
  $seckeyadjustedfirst12 = substr($seckeyadjusted, 0, 12);

  $encryptionkey = $seckeyadjustedfirst12.$hashedkeylast12;
  return $encryptionkey;

}



function encrypt3Des($data, $key)
 {
  $encData = openssl_encrypt($data, 'DES-EDE3', $key, OPENSSL_RAW_DATA);
        return base64_encode($encData);
 }




function payViaUssd(){ // set up a function to test card payment.
    
    error_reporting(E_ALL);
    ini_set('display_errors',1);
    
    $data = array('PBFPubKey' => 'FLWPUBK-e634d14d9ded04eaf05d5b63a0a06d2f-X',
    'currency' => 'ZAR',
    'amount' => '100',
    'country' => 'ZA',
    'firstname' => 'Edward',
    'lastname' => 'Kisane',
    'email' => '[email protected]',
    'pin' =>  "19203804939000",
    'phonenumber': '09283730923',              
    'IP' => '103.238.105.185',
    'txRef' => 'MXX-ASC-4578',
    'is_flash_voucher' => 1,
    'device_fingerprint' => '69e6b7f0sb72037aa8428b70fbe03986c');
    
    $SecKey = 'FLWSECK-bb971402072265fb156e90a3578fe5e6-X';
    
    $key = getKey($SecKey); 
    
    $dataReq = json_encode($data);
    
    $post_enc = encrypt3Des( $dataReq, $key );

    var_dump($dataReq);
    
    $postdata = array(
     'PBFPubKey' => 'FLWPUBK-e634d14d9ded04eaf05d5b63a0a06d2f-X',
     'client' => $post_enc,
     'alg' => '3DES-24');
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "https://api.ravepay.co/flwv3-pug/getpaidx/api/charge");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata)); //Post Fields
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200);
    curl_setopt($ch, CURLOPT_TIMEOUT, 200);
    
    
    $headers = array('Content-Type: application/json');
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $request = curl_exec($ch);
    
    if ($request) {
        $result = json_decode($request, true);
        echo "<pre>";
        print_r($result);
    }else{
        if(curl_error($ch))
        {
            echo 'error:' . curl_error($ch);
        }
    }
    
    curl_close($ch);
}

payViaUssd();

Step 2: Call the charge endpoint with your encrypted data

https://api.ravepay.co/flwv3-pug/getpaidx/api/charge

Method: POST

$postdata = array(
     'PBFPubKey' => 'FLWPUBK-e634d14d9ded04eaf05d5b63a0a06d2f-X',
     'client' => $post_enc,
     'alg' => '3DES-24');
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "https://api.ravepay.co/flwv3-pug/getpaidx/api/charge");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata)); //Post Fields
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200);
    curl_setopt($ch, CURLOPT_TIMEOUT, 200);
    
    
    $headers = array('Content-Type: application/json');
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $request = curl_exec($ch);
    
    if ($request) {
        $result = json_decode($request, true);
        echo "<pre>";
        print_r($result);
    }else{
        if(curl_error($ch))
        {
            echo 'error:' . curl_error($ch);
        }
    }
    
    curl_close($ch);
}

payViaUssd();

Then we call your webhook once the transaction has been completed with a successful response.

{
    "status": "success",
    "message": "V-COMP",
    "data": {
        "id": 884379,
        "txRef": "Rave-1920280383392",
        "orderRef": "URF_1572898357545_7845335",
        "flwRef": "FLW229221572898359918",
        "redirectUrl": "N/A",
        "device_fingerprint": "N/A",
        "settlement_token": null,
        "cycle": "one-time",
        "amount": 100,
        "charged_amount": 100,
        "appfee": 1.4,
        "merchantfee": 0,
        "merchantbearsfee": 1,
        "chargeResponseCode": "00",
        "raveRef": "RV31572898357027C49BF6C7E7",
        "chargeResponseMessage": "Transaction Successful",
        "authModelUsed": "AUTH",
        "currency": "ZAR",
        "IP": "::ffff:10.79.182.75",
        "narration": "Raver",
        "status": "successful",
        "modalauditid": "466efc1a373e7aec181e70d4b3e39461",
        "vbvrespmessage": "N/A",
        "authurl": "NO-URL",
        "vbvrespcode": "N/A",
        "acctvalrespmsg": null,
        "acctvalrespcode": null,
        "paymentType": "1voucher",
        "paymentPlan": null,
        "paymentPage": null,
        "paymentId": "N/A",
        "fraud_status": "ok",
        "charge_type": "normal",
        "is_live": 0,
        "retry_attempt": null,
        "getpaidBatchId": null,
        "createdAt": "2019-11-04T20:12:37.000Z",
        "updatedAt": "2019-11-04T20:12:41.000Z",
        "deletedAt": null,
        "customerId": 212688,
        "AccountId": 21690,
        "customer": {
            "id": 212688,
            "phone": "271000010010",
            "fullName": "Some body",
            "customertoken": null,
            "email": "[email protected]",
            "createdAt": "2019-11-04T20:12:37.000Z",
            "updatedAt": "2019-11-04T20:12:37.000Z",
            "deletedAt": null,
            "AccountId": 21690
        }
    }
}
{
  "id": 126090,
  "txRef": "Rave-1920280383392",
  "flwRef": "FLW393751572018402410",
  "orderRef": URF_1572018401297_2169035,
  "paymentPlan": null,
  "createdAt": "2019-10-25T15:46:41.000Z",
  "amount": 2000,
  "charged_amount": 2000,
  "status": "successful",
  "IP": "197.149.95.62",
  "currency": "ZAR",
  "customer": {
    "id": 22823,
    "phone": "0902620185",
    "fullName": "Temi Desola",
    "customertoken": null,
    "email": "[email protected]",
    "createdAt": "2018-04-08T10:28:01.000Z",
    "updatedAt": "2018-04-08T10:28:01.000Z",
    "deletedAt": null,
    "AccountId": 134
  },
  "entity": {
    "id": "NO-ENTITY"
  }
}

Great you are almost done, now you need to verify the transaction before giving value for this transaction.

Step 3: Verify the payment.

After charging a customer successfully, you need to verify that the payment was successful with Rave before giving value to your customer on your website.

Below are the important things to check for when validating the payment:

Verify the transaction reference.

Verify the data.status of the transaction to be successful.

Verify the currency to be the expected currency

Most importantly validate the amount paid to be equal to or at least greater than the amount of the value to be given.

Below is sample code of how to implement server side validation in different programming languages

curl --request POST \
  --url https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify \
  --header 'content-type: application/json' \
  --data '{"txref":"Rave-1920280383392","SECKEY":"FLWSECK-e6db11d1f8a6208de8cb2f94e293450e-X"}'
<?php 

$result = array();

$postdata =  array( 
  'txref' => 'Rave-1920280383392',
  'SECKEY' => 'FLWSECK-e6db11d1f8a6208de8cb2f94e293450e-X'
  );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($postdata));  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
  'Content-Type: application/json',
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$request = curl_exec ($ch);
$err = curl_error($ch);

if($err){
	// there was an error contacting rave
  die('Curl returned error: ' . $err);
}


curl_close ($ch);

$result = json_decode($request, true);

if('error' == $result->status){
  // there was an error from the API
  die('API returned error: ' . $result->message);
}

if('successful' == $result->data->status && '00' == $result->data->chargecode){
  // transaction was successful...
  // please check other things like whether you already gave value for this ref
  // If the amount and currency matches the expected amount and currency etc.
  // if the email matches the customer who owns the product etc
  // Give value
}
//Endpoint to verify transaction
    private final String VERIFY_ENDPOINT = "https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify"; 
    
    /**
     * 
     * Method to 
     * 
     * @param paymententity - <b>paymententity - set as a constant with default value as 1</b>
     * @param txref - <b>txref - is the unique payment reference generated by the merchant.</b>
     * @param secret - <b>secret - is the merchant secret key</b>
     * @return
     * @throws UnirestException 
     */
    public JSONObject verify(String flwRef, String secret, double amount, int paymententity) throws UnirestException, Exception {
        
        // This packages the payload
        JSONObject data = new JSONObject();
        data.put("txref", txref);
        data.put("SECKEY", secret)
        
        // end of payload
        
        // This sends the request to server with payload
        HttpResponse<JsonNode> response = Unirest.post(VERIFY_ENDPOINT)
                .header("Content-Type", "application/json")
                .body(data)
                .asJson();
        
        // This get the response from payload
        JsonNode jsonNode = response.getBody();
        
        // This get the json object from payload
        JSONObject responseObject = jsonNode.getObject();
        
        // check of no object is returned
        if(responseObject == null)
            throw new Exception("No response from server");
        
        // This get status from returned payload
        String status = responseObject.optString("status", null);
        
        // this ensures that status is not null
        if(status == null)
            throw new Exception("Transaction status unknown");
        
        // This confirms the transaction exist on rave
        if(!"success".equalsIgnoreCase(status)){
            
            String message = responseObject.optString("message", null);
            
            throw new Exception(message);
        }
        
        data = responseObject.getJSONObject("data");
        
        // This get the amount stored on server
        double actualAmount = data.getDouble("amount");
        
        // This validates that the amount stored on client is same returned
        if(actualAmount != amount)
            throw new Exception("Amount does not match");
        
        
        // now you can give value for payment.
       
    }
var data = new {txref = "Rave-1920280383392", SECKEY = "FLWSECK-e6db11d1f8a6208de8cb2f94e293450e-X"};
            var client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var responseMessage = client.PostAsJsonAsync("https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify", data).Result;
            var responseStr = responseMessage.Content.ReadAsStringAsync().Result;
            var response = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseData>(responseStr);
            if (response.data.status == "successful" && response.data.amount == amount && response.data.chargecode == "00")
            {
              
              System.Console.WriteLine("Payment Successful then give value");
               
            }

When you successfully verify a completed payment see sample response below:

{
    "status": "success",
    "message": "Tx Fetched",
    "data": {
        "txid": 884379,
        "txref": "Rave-1920280383392",
        "flwref": "FLW229221572898359918",
        "devicefingerprint": "N/A",
        "cycle": "one-time",
        "amount": 100,
        "currency": "ZAR",
        "chargedamount": 100,
        "appfee": 1.4,
        "merchantfee": 0,
        "merchantbearsfee": 1,
        "chargecode": "00",
        "chargemessage": "Transaction Successful",
        "authmodel": "AUTH",
        "ip": "::ffff:10.79.182.75",
        "narration": "Raver",
        "status": "successful",
        "vbvcode": "N/A",
        "vbvmessage": "N/A",
        "authurl": "NO-URL",
        "acctcode": null,
        "acctmessage": null,
        "paymenttype": "1voucher",
        "paymentid": "N/A",
        "fraudstatus": "ok",
        "chargetype": "normal",
        "createdday": 1,
        "createddayname": "MONDAY",
        "createdweek": 45,
        "createdmonth": 10,
        "createdmonthname": "NOVEMBER",
        "createdquarter": 4,
        "createdyear": 2019,
        "createdyearisleap": false,
        "createddayispublicholiday": 0,
        "createdhour": 20,
        "createdminute": 12,
        "createdpmam": "pm",
        "created": "2019-11-04T20:12:37.000Z",
        "customerid": 212688,
        "custphone": "271000010010",
        "custnetworkprovider": "UNKNOWN PROVIDER",
        "custname": "Some body",
        "custemail": "[email protected]",
        "custemailprovider": "COMPANY EMAIL",
        "custcreated": "2019-11-04T20:12:37.000Z",
        "accountid": 21690,
        "acctbusinessname": "Raver",
        "acctcontactperson": "Desola Adesina",
        "acctcountry": "NG",
        "acctbearsfeeattransactiontime": 1,
        "acctparent": 2410,
        "acctvpcmerchant": "N/A",
        "acctalias": null,
        "acctisliveapproved": 0,
        "orderref": "URF_1572898357545_7845335",
        "paymentplan": null,
        "paymentpage": null,
        "raveref": "RV31572898357027C49BF6C7E7",
        "amountsettledforthistransaction": 98.6,
        "meta": []
    }
}