tolu360 / react-native-paystack

React Native Wrapper for the Paystack Native Mobile SDKs
162 stars 48 forks source link

you should call init first higer up your code https://github.com/tolu360/react-native-paystack#3-usage #25

Closed adeojoemmanuel closed 5 years ago

adeojoemmanuel commented 5 years ago

i get the error

you should call init first higer up your code https://github.com/tolu360/react-native-paystack#3-usagei get this error "

even after calling

RNPaystack.init({ publicKey: 'pk_live_7df3a55391cd5a9dc3fe2eeb27a20d3d295feb0d' });

right benit my import

samie820 commented 5 years ago

Hi, please can you show the full .js file where you are calling RNPaystack.init, the issue might be where you are calling it from

onyiiamala commented 5 years ago

I did not call

hammedismail54 commented 5 years ago

Helo pls I have issue on dis help me resolve it i get the error

`you should call init first higer up your code https://github.com/tolu360/react-native-paystack#3-usagei get this error screenshot_2019-02-02-21-32-35

samie820 commented 5 years ago

Helo pls I have issue on dis help me resolve it i get the error

`you should call init first higer up your code https://github.com/tolu360/react-native-paystack#3-usagei get this error screenshot_2019-02-02-21-32-35

Hi @hammedismail54, Can you share a screenshot of where you are calling RNPaystack.init({ publicKey: 'YOUR_PUBLIC_KEY_HERE' });?

samie820 commented 5 years ago

I did not call Hi @onyiiamala, You should actually, when using the library you have to first call RNPaystack.init({ publicKey: 'YOUR_PUBLIC_KEY_HERE' }); higher up in your codebase (maybe in your componentDidMount or your constructor)

hammedismail54 commented 5 years ago

Hw do I call RNPaystack.init

onyiiamala commented 5 years ago

How do i call init

onyiiamala commented 5 years ago

How can i get the loan without calling init because i don't even know how to call init

samie820 commented 5 years ago

Step 1: Create a JS file and paste the JS class below

import RNPaystack from 'react-native-paystack';

/**
 * This class handles all implementation details used to communicate with paystack
 * @class
 * @param  {} onSuccessFunction Callback function to be called when the transaction and verification is successful
 * @param  {} onErrorFunction Callback function to be called when the transaction and/or verrification fails
 */
export class Paystack {
  constructor(onSuccessFunction, onErrorFunction, sandboxMode = false) {
    this.onSuccessFunction = onSuccessFunction;
    this.onErrorFunction = onErrorFunction;
    RNPaystack.init({
      publicKey: '<ENTER_PUBLIC_KEY_FROM_PAYSTACK_HERE>',
    });
    this.sandboxMode = sandboxMode;
  }

  // function that calls the paystack verification endpoint
  verifyTransaction = (referenceID) => {
    fetch('<PAYSTACK_VERIFICATION_URL_WITH_REFERENCE_ID>', {
      headers: { <read paystack documentattion to know which header to use here >},
    })
      .then(responsePlain => responsePlain.json())
      .then((response) => {
        const { data } = response;
        if (response.status && data.status === 'success') {
          this.onSuccessFunction(response);
        } else {
          this.onErrorFunction(response);
        }
      })
      .catch(error => this.onErrorFunction(error));
  };

  // removes object values with empty strings
  cleanObjectPayload = (payload) => {
    const keys = Object.keys(payload);
    const payloadToSend = {};
    keys.forEach((key) => {
      if (payload[key] !== '') {
        payloadToSend[key] = payload[key];
      }
    });
    return payloadToSend;
  };

  // function that actually charges the card
  chargeCard({
    cardNumber = '',
    expiryMonth = '',
    expiryYear = '',
    cvc = '',
    email = '',
    amountInKobo = '',
    subAccount = '',
  } = {}) {
    const inputToSend = this.cleanObjectPayload({
      cardNumber: cardNumber,
      expiryMonth,
      expiryYear,
      cvc,
      email,
      amountInKobo,
      subAccount,
    });

    console.log(inputToSend);
    RNPaystack.chargeCard(inputToSend)
      .then((response) => {
        if (this.sandboxMode) {
          this.onSuccessFunction(response);
        } else {
          this.verifyTransaction(response.reference);
        }
      })
      .catch((error) => {
        this.onErrorFunction(error);
      });
  }
}

export default Paystack;

Then use it like below in your React class:

  constructor(props) {
    super(props);
    this.paystack = new PaystackService(this.onSuccess, this.onError, true);
  }

  onSuccess = (data) => {
 // function to run if the transaction is successful
  };

  onError = (error) => {
 // handle the error if the payment fails
  };

  handlePayment = () => {
    this.paystack.chargeCard({
      cardNumber: 3222333300987776,
      expiryMonth: 12,
      expiryYear: 30,
      cvc: 110,
      email: '<email address>',
      amountInKobo: 5000000,
    });
  };
oseme2 commented 5 years ago

I don't even understand what to do

oseme2 commented 5 years ago

Because I got the same init error

oseme2 commented 5 years ago

Where do I create js

samie820 commented 5 years ago

Where do I create js Wherever you want, you can place it in any folder within your project and import it into where you want to use it

oseme2 commented 5 years ago

Good day, i actually applied for a loan on soft cash and it came up so how do i use it on the app

On Fri, Feb 8, 2019, 4:12 PM sammy <notifications@github.com wrote:

Where do I create js Wherever you want, you can place it in any folder within your project and import it into where you want to use it

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tolu360/react-native-paystack/issues/25#issuecomment-461834375, or mute the thread https://github.com/notifications/unsubscribe-auth/AtQV-S9o3ChtvUSiiVSAeiMKobWvpTGkks5vLZP0gaJpZM4aGgtr .

oseme2 commented 5 years ago

can you please help me with this?

On Fri, Feb 8, 2019, 4:16 PM paul itoadon <paulitoadon@gmail.com wrote:

Good day, i actually applied for a loan on soft cash and it came up so how do i use it on the app

On Fri, Feb 8, 2019, 4:12 PM sammy <notifications@github.com wrote:

Where do I create js Wherever you want, you can place it in any folder within your project and import it into where you want to use it

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tolu360/react-native-paystack/issues/25#issuecomment-461834375, or mute the thread https://github.com/notifications/unsubscribe-auth/AtQV-S9o3ChtvUSiiVSAeiMKobWvpTGkks5vLZP0gaJpZM4aGgtr .

oseme2 commented 5 years ago

please can i get a step by step on how to go about this?

On Fri, Feb 8, 2019, 4:18 PM paul itoadon <paulitoadon@gmail.com wrote:

can you please help me with this?

On Fri, Feb 8, 2019, 4:16 PM paul itoadon <paulitoadon@gmail.com wrote:

Good day, i actually applied for a loan on soft cash and it came up so how do i use it on the app

On Fri, Feb 8, 2019, 4:12 PM sammy <notifications@github.com wrote:

Where do I create js Wherever you want, you can place it in any folder within your project and import it into where you want to use it

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tolu360/react-native-paystack/issues/25#issuecomment-461834375, or mute the thread https://github.com/notifications/unsubscribe-auth/AtQV-S9o3ChtvUSiiVSAeiMKobWvpTGkks5vLZP0gaJpZM4aGgtr .

steveamaza commented 5 years ago

@hammedismail54 @oseme2 @onyiiamala

This is a library for developers integrating Paystack not for customers of a merchant using Paystack. Please reach out to the support team of the business you are trying to get a loan from so they can help you. This discussion is for developers

oseme2 commented 5 years ago

okay sir/ma

On Sun, Feb 10, 2019, 8:48 AM Stephen Amaza <notifications@github.com wrote:

@hammedismail54 https://github.com/hammedismail54 @oseme2 https://github.com/oseme2 @onyiiamala https://github.com/onyiiamala

This is a library for developers integrating Paystack not for customers of a merchant using Paystack. Please reach out to the support team of the business you are trying to get a loan from so they can help you. This discussion is for developers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tolu360/react-native-paystack/issues/25#issuecomment-462111290, or mute the thread https://github.com/notifications/unsubscribe-auth/AtQV-RHwXF1o-3qqAyQVhqB3iD2h0TYlks5vL87JgaJpZM4aGgtr .

onyiiamala commented 5 years ago

I need a loan from your company, but each time i applied, i always receive increase your Init code. Please what does that stands for?

onyiiamala commented 5 years ago

I need a loan from your company, but each time i applied, i always receive increase your Init code. Please what does that stands for?

steveamaza commented 5 years ago

@tolu360 can you please call this issue :) @onyiiamala please email support@paystack.com

twenty9canmakeit commented 5 years ago

Am getting issue on my softcash app when applying for a load after filling every details its indicating I should call init can someone explain to me better how I can go about it.

tolu360 commented 5 years ago

Hi Softcash Dev, please update your app and stop showing these errors to your users - they are mainly just for your benefits. Thank you!