ashinzekene / angular-rave

💵 An angular2+ module for integrating payments using the rave gateway
https://ashinzekene.github.io/angular-rave
MIT License
22 stars 14 forks source link
angular credit-card flutterwave gateway module money nigeria payments rave ravepay transaction

ANGULAR-RAVE

Easily intergrate the rave payment gateway in your angular2+ project

HOW TO USE

You can checkout the demo here

1. Install the module

Run this in the root of your angular project

  npm install --save angular-rave

2. Import the module into your project like so

  import { NgModule } from '@angular/core';
  import { AngularRaveModule } from 'angular-rave';
  ...

  @NgModlule({
    imports: [
      AngularRaveModule.forRoot('FLWPUBK-XXXXXXXXXXXXXXXXXXX'),
    ]
  })

where FLWPUBK-XXXXXXXXXXXXXXXXXXX is your public key which can be found on the flutterwave dashboard

3. Implementing Angular-rave

There are two option available

  1. The angular-rave directive:
    <button
    angular-rave
    [customer]="{ email: 'user@example.com', phonenumber: '0809808800900' }"
    [amount]="500000"
    [customizations]="{ title: 'Bill Payment'}"
    [tx_ref]="'USR1295950'"
    (callback)="paymentSuccess($event)"
    (close)="paymentFailure()"
    (init)="paymentInit()"
    >PAY NOW</button>

    And then in your component.ts file:

import { Component } from '@angular/core';
import { RavePaymentData } from 'angular-rave';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  paymentFailure() {
    console.log('Payment Failed');
  }

  paymentSuccess(res: RavePaymentData) {
    console.log('Payment complete', res);
    // Verify the transaction
  }

  paymentInit() {
    console.log('Payment about to begin');
  }
}

Rave Options

You can also pass in an object containing your rave options like so

<button
  angular-rave
  [raveOptions]="raveOptions"
  (init)="paymentInit()"
  (callback)="paymentSuccess($event)"
  (onclose)="paymentFailure()"
>
  Pay with Rave Directive
</button>

And then you can import the RaveOptions class for help in typing

import { RaveOptions } from 'angular-rave';

...
  raveOptions: RaveOptions = {
    amount: 3000,
    customer: {
      email: 'user@ravemail.com',
      phonenumber: '09010910901',
      name: 'Ekene Ashinze',
    },
    customizations: {
      description: 'This is a flutterwave modal implemented using angular rave',
      title: 'Angular Rave',
      logo: 'https://angular.io/assets/images/logos/angular/angular.svg',
    },
    tx_ref: `${Math.random() * 1000000}`,
  };

And then in the template

<button
  angular-rave
  [autoClose]="true"
  [raveOptions]="raveOptions"
>PAY NOW</button>

Rave Key Specificity

Also, you can pass in a key in the component and the directive, in such situation, this key is given a higher preference over the global forRoot key. For example, if you have this is your module file

@NgModule({
  imports: [
    AngularRaveModule.forRoot('FLWPUBK-1000'),
  ]
})

and this in your component

<button
  angular-rave
  [public_key]="FLWPUBK-2000"
  [raveOptions]="paymentOptions"
>
  PAY NOW
</button>

Then FLWPUBK-2000 would be used instead

NOTE:

OPTIONS

Name Type Required Default Value Description
public_key string true - Merchant public key
tx_ref string true - Your transaction reference. This MUST be unique for every transaction
amount number true - Amount to charge the customer.
currency string false 'NGN' currency to charge in. Defaults to 'NGN'
integrity_hash string false - This is a sha256 hash of your FlutterwaveCheckout values, it is used for passing secured values to the payment gateway.
paymentOptions PaymentOptionsEnum[] false - This specifies the payment options to be displayed e.g - card, mobilemoney, ussd and so on.
payment_plan string false - This is the payment plan ID used for Recurring billing
subaccounts RaveSubAcccount[] false - This is an array of objects containing the subaccount IDs to split the payment into. Check our Split Payment page for more info
redirect_url string false - URL to redirect to when a transaction is completed. This is useful for 3DSecure payments so we can redirect your customer back to a custom page you want to show them.
customer RaveCustomer true - This is an object that can contains your customer details: e.g: { 'email': 'example@example.com', 'phonenumber': '08012345678', 'name': 'Takeshi Kovacs'}
meta {[key: string]: any} false - This is an object that helps you include additional payment information to your request {'consumer_id': 23,'consumer_mac': '92a3-912ba-1192a'}
customizations RaveCustomization true - This is an object that contains title, logo, and description you want to display on the modal e.g {'title': 'Pied Piper Payments', 'description': 'Middleout isn't free. Pay the price', 'logo': 'https://assets.piedpiper.com/logo.png'}
init () => void false - A function to be called when payment is about to begin
onclose function() false - A function to be called when the pay modal is closed before a transaction is completed.
callback (res: RavePaymentData) => void true - A function to be called on successful card charge. Users can always be redirected to a successful or failed page supplied by the merchant here based on response.

You can get more information from rave's documentation
Type definitions can be found here

CONTRIBUTING

Feel free to create issues and submit pull requests to make corrections or enhance functionality

Two projects exist in this repository

Angular-rave project

Demo

Release

Thanks! Ashinze Ekene.

License

The MIT License (MIT). Please see License File for more information.