Rave.NET
.NET Standard API for interfacing with Rave (Flutterwave's payment gateway)
Install / Use
/learn @DaraOladapo/Rave.NETREADME
Rave.NET
.NET Standard API for interfacing with Rave (Flutterwave's payment gateway)
The following was copied as is from the offical project found here with modifications.
Introduction
The Rave .NET Library implements the following payment services:
- Card Payments
- Bank Account Payments.
- Mobile Money Payments.
- Bank Transfer (NGN).
- Subscriptions.
- Virtual Cards.
The Library also implements the following features:
- Tokeniztion
- Subaccounts
- Currencies.
- Pre-Authorisation.
- Refunds.
Prerequisites
- .NET Standard 2.0+
Installation
Using .NET CLI
dotnet add package Rave.NET --version 1.0.2
Using Package Manager Console
Install-Package Rave.NET -Version 1.0.2
Using Package Reference
<PackageReference Include="Rave.NET" Version="1.0.2" />
Using Paket CLI
paket add Rave.NET --version 1.0.2
Usage
- Import Namespaces
using Rave.NET.API;
using Rave.NET.Models.Card;
using Rave.NET.Models.Charge;
-
Set up Rave Configuration
Rave Config takes in 3 arguments
- PbKey: Public key
- ScKey: Secret Key
- false/true: false if test key, true if live keys
private static RaveConfig raveConfig = new RaveConfig(PbKey, ScKey, false);
- Create Card Create a card taking in your user's input
private static Card card = new Card(CardNumber, ExpiryMonth, ExpiryYear, CVV);
- Create payload and card charge for Rave API
private static CardParams payload = new CardParams(PbKey, ScKey, "Anonymous", "Tester", "user@example.com", 50000, "NGN", card) { TxRef = tranxRef };
private static ChargeCard cardCharge = new ChargeCard(raveConfig);
- Charge Card
RaveResponse<ResponseData> chargeResult = new API.RaveResponse<ResponseData>();
chargeResult = await cardCharge.Charge(payload);
- The following logic will be based on the result of the charge. The code sample below was written for Xamarin.Forms
if (chargeResult.Message == "AUTH_SUGGESTION" && chargeResult.Data.SuggestedAuth == "PIN")
{
PINEntryPanel.IsVisible = true;
}
else
{
await DisplayAlert(chargeResult.Status, chargeResult.Message, "OK");
}
Next step if the charge requires a PIN
payload.Pin = "3310";
payload.SuggestedAuth = "PIN";
if (chargeResult.Message == "AUTH_SUGGESTION" && chargeResult.Data.SuggestedAuth == "OTP")
{
OTPEntryPanel.IsVisible = true;
}
else
{
await DisplayAlert(chargeResult.Status, chargeResult.Message, "OK");
}
If an OTP is required
payload.SuggestedAuth = "OTP";
payload.Otp = "12345";
chargeResult = await cardCharge.Charge(payload);
await DisplayAlert(chargeResult.Status, chargeResult.Message, "OK");
Happy Usage. 😍
<!-- ## Configuration Add all relevant modules ```bash using System.Diagnostics; using System.Collections.Generic; using Rave.NET.Models.MobileMoney; using Rave.NET.Models.VirtualCard; using Rave.NET.Models.Subaccount; using Rave.NET.Models.Tokens; using Rave.NET.Models; using Rave.NET.Models.Charge; using Rave.NET.Models.Account; using Rave.NET.Models.Card; using Rave.NET.Models.Validation; using NUnit.Framework; ``` Pass Public and Secret keys as variables for configuration. ```bash private static string PbKey = "pass your public key here" private static string ScKey = "pass your secret key here" var raveConfig = new RaveConfig(PbKey, SCKey, false); ``` # Payments ## Card Payments This implements Card payments for Pin, 3D-Secure, VBV and PreAuth transactions. ## Usage 1. Complete basic configuration following the configuration steps. 2. Configure the card charge ```bash var cardCharge = new ChargeCard(raveConfig); ``` 3. Pass Card parameters as payload. The payload should contain: - `Public key` - `First name` - `Last name` - `Email address` - `Amount` - `Card details.` These card details include: - `Card number` - `CVV` - `Expiry month` - `Expiry year` - `Trans Ref` ```bash var Payload = new CardParams(PbKey, "Anonymous", "Customer", "tester@example.com", 2100){ cardNo = "5438898014560229", Cvv = "789", Expirymonth = "09", Expiryyear = "19", TxRef = tranxRef} ``` 4. Charge card. ```bash var cha = cardCharge.Charge(Payload).Result; ``` 5. Pass Pin and OTP to complete the Transaction ```bash if (cha.Message == "AUTH_SUGGESTION" && cha.Data.SuggestedAuth == "PIN") { cardParams.Pin = "3310"; cardParams.Otp = "12345"; cardParams.SuggestedAuth = "PIN"; cha = cardCharge.Charge(Payload).Result; } ``` **The complete card charge and validation flow:** ```bash class Program { private static string tranxRef = "454839"; private static string PbKey = ""; private static string ScKey = ""; static void Main(string[] args) { var raveConfig = new RaveConfig(PbKey, ScKey, false); var cardCharge = new CardCharge(raveConfig); var Payload = new CardChargeParams(PbKey, "Anonymous", "Customer", "tester@example.com", 2100) { CardNo = "5438898014560229", Cvv = "789", Expirymonth = "09", Expiryyear = "19", TxRef = tranxRef } ; var cha = cardCharge.Charge(cardParams).Result; if (cha.Message == "AUTH_SUGGESTION" && cha.Data.SuggestedAuth == "PIN") { cardParams.Pin = "3310"; cardParams.Otp = "12345"; cardParams.SuggestedAuth = "PIN"; cha = cardCharge.Charge(Payload).Result; } } } ``` ## Account Payments This implements direct debit transactions from Bank accounts. ### Usage 1. Complete basic configuration following the configuration steps. 2. Configure the Account charge ```bash var accountCharge = new ChargeAccount(raveConfig); ``` 3. Pass Account parameters as payload. The payload should contain: - `Public key` - `First name` - `Last name` - `Email address` - `Account number` - `Amount` - `Bank code.` - `Currency (NGN)` - `Trans Ref` ```bash var Payload = new AccountParams(PbKey, "Anonymous", "customer", "user@example.com", "0690000031", 1000.00m, "044", "NGN", "MC-0292920"); ``` 4. Charge Account. ```bash var chargeResponse = await accountCharge.Charge(accountParams); if (chargeResponse.Data.Status == "success-pending-validation") { // This usually means the user needs to validate the transaction with an OTP accountParams.Otp = "12345"; chargeResponse = accountCharge.Charge(accountParams).Result; } Trace.WriteLine(chargeResponse.Data.ValidateInstructions.Instruction); Trace.WriteLine(chargeResponse.Data.ValidateInstructions.Valparams); Trace.WriteLine(chargeResponse.Data.ValidateInstruction); ``` **The complete card charge and validation flow:** ```bash class Program { private static string tranxRef = "454839"; private static string PbKey = ""; private static string ScKey = ""; static void Main(string[] args) { var raveConfig = new RaveConfig(recurringPbKey, recurringScKey, false); var accountCharge = new ChargeAccount(raveConfig); var Payload = new AccountParams(PbKey, "Anonymous", "customer", "user@example.com", "0690000031", 1000.00m, "044", "MC-0292920"); var chargeResponse = await accountCharge.Charge(accountParams); if (chargeResponse.Data.Status == "success-pending-validation") { // This usually means the user needs to validate the transaction with an OTP accountParams.Otp = "12345"; chargeResponse = accountCharge.Charge(accountParams).Result; } Trace.WriteLine(chargeResponse.Data.ValidateInstructions.Instruction); Trace.WriteLine(chargeResponse.Data.ValidateInstructions.Valparams); Trace.WriteLine(chargeResponse.Data.ValidateInstruction); ValidateAccountCharge(chargeResponse.Data.FlwRef); } } ``` ## Mobile Money Payments This implements Mpesa, Ghana, Uganda, Zambia and Rwanda Mobile money transactions for customers. ## Usage 1. Complete basic configuration following the configuration steps. 2. Configure the Mobile money charge ```bash var mobilemoney = new ChargeMobileMoney(raveConfig); ``` 3. Pass mobile money parameters as payload. The payload should contain: - `Public key` - `Secret key` - `First name` - `Last name` - `Email address` - `Amount` - `Currency` - `Mobile number` - `Network` - `Country` - `Payment Type` - `Trans Ref` ```bash var Payload = new MobileMoneyParams(PbKey, ScKey, "Anonymous", "customer", "user@example.com", 1055, "GHS", "054709929220", "network", "country", "paymentType", "MC-0292920"); ``` The payload parameters differ for different countries, currencies and payment types. | Country | Payment Type | Country code | Currency | Network | | ------- | ------------ | ------------ | -------- | ------- | | Ghana | `mobilemoneygh` | `GH` | GHS | `MTN, VODAFONE, TIGO` | | Kenya | `mpesa` | `KE` | KES | | Rwanda | `mobilemoneygh` | `NG` | RWF | `RWF` | | Zambia | `mobilemoneyzambia` | `NG` | ZMW | `MTN` | | Uganda | `mobilemoneyuganda` | `UG` | UGX | `UGX` | 4. Carry out mobile money charge ```bash var cha = mobilemoney.Charge(Payload).Result; ``` **The Complete flow for mobile money charge:** ```bash class Program { private static string tranxRef = "454839"; private static string PbKey = ""; private static string ScKey = ""; static