lordmaul
lordmaul

Reputation: 29

How to get token in flutterwave, using PHP

I am working with the flutterwave payment gateway, following the instructions on their docs http://docs.flutterwave.com/card-payments/#tokenize-and-charge I have the following code which apparently is supposed to return a token with which I can charge the user.

 require_once("../../lib/functions.php");

    // The data to send to the API
    $merchantKey = "****";
    $apiKey = "*****";
    $card = [
        "amount"=> encrypt3Des("200", $apiKey),
        "authmodel"=> encrypt3Des("PIN", $apiKey),
        "cardno"=> encrypt3Des("***********", $apiKey),
        "currency"=> encrypt3Des("NGN", $apiKey),
        "custid"=> encrypt3Des("11232", $apiKey),   
        "cvv"=> encrypt3Des("***", $apiKey),
        "pin"=> encrypt3Des("***", $apiKey),//"(Optional:Only needed where authmodel is PIN) Encrypted PIN",
        //"bvn"=> "(Optional:Only needed where authmodel is BVN) Encrypted BVN",

        "expirymonth"=> encrypt3Des("**", $apiKey),//"Encrypted Expiry Month",
        "expiryyear"=> encrypt3Des("****", $apiKey), //"Encrypted Expiry Year",
        "merchantid"=> $merchantKey,//"Merchant Key",
        "narration"=> encrypt3Des("Payment for service", $apiKey),//"Encrypted Narration",
    ];

// Setup cURL
$ch = curl_init('http://staging1flutterwave.co:8080/pwc/rest/card/mvva/pay');
curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array(
        //'Authorization: '.$authToken,
        'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => json_encode($card)
));

// Send the request
$response = curl_exec($ch);

// Check for errors
if($response === FALSE){
    die(curl_error($ch));
}

// Decode the response
$responseData = json_decode($response, TRUE);
var_dump($responseData);
// Print the date from the response
//echo $responseData['published'];

but it responds with the following

array(2) { ["data"]=> array(6) { ["responsecode"]=> string(5) "RR-R3" ["responsemessage"]=> string(50) "Sorry, you need to add 'CardToken' to your request" ["otptransactionidentifier"]=> NULL ["transactionreference"]=> string(4) "null" ["responsehtml"]=> NULL ["responsetoken"]=> NULL } ["status"]=> string(7) "success" }

What am I missing here?

Upvotes: 3

Views: 822

Answers (1)

Joseph Olaoye
Joseph Olaoye

Reputation: 11

lordmaul

why not try the Flutterwave PHP library available at https://github.com/flutterwave/flutterwave-php.

It is easier to see what your payload is and also debug.

Also, kindly note that the PIN Auth Model does not work with VISA Cards, Use either BVN, VBVSECURECODE or RANDOM_DEBIT as Auth Model if you are testing with a Visa Card.

Upvotes: 1

Related Questions