Git Product home page Git Product logo

Comments (9)

Onyelaudochukwuka avatar Onyelaudochukwuka commented on September 23, 2024 3

Exactly, I had to switch a single component to JavaScript before I could launch for production

from react-paystack.

somteacodes avatar somteacodes commented on September 23, 2024 1

Taking a hint from @Onyelaudochukwuka
a workaround is to extract the payment logic to a child component in JavaScript instead of a typescript component, as the issue is from incorrect typings from the package.
In this example I used the hook method, but same logic sould apply to using the button method
Parent Component named PaymentPage.tsx name an be called anything

import PaymentWithPaystack from './components/PaymentWithPaystack'
  interface PaymentRef {
    message: string;
    redirecturl: string;
    reference: number;
    status: string;
    trans: number;
    transaction: number;
    trxref: number;
  }
const PaymentPage= () =>{
  const paymentResponse = (ref: PaymentRef )=>{  
      console.log(ref);
    }
    return (
    <>
    //....Other components
    <PaymentWithPaystack amount={300000} paymentResponse={paymentResponse}/>
    </>
    )
}
export default PaymentPage;

Child Component named PaymentWithPaystack.js name can be called anything

import { usePaystackPayment } from 'react-paystack';

const PaymentWithPaystack = ({amount=0, paymentResponse }) => {
  const config = {
    reference: (new Date()).getTime().toString(),
    email: "[email protected]",
    amount: amount,
    publicKey: 'pk_test_.........',
  };
  
  // you can call this function anything
  const handleSuccess = (ref) => {
  // Implementation for whatever you want to do with reference and after success call.
  //  console.log(ref);
   paymentResponse(ref)
   
  };
  
  // you can call this function anything
  const onClose = () => {
  // implementation for  whatever you want to do when the Paystack dialog closed.
  console.log('closed')
  }
  
  const PaystackHookExample = () => {
    const initializePayment = usePaystackPayment(config);
    return (
      <div>
          <button onClick={() => {
              initializePayment(handleSuccess, onClose)
          }}>Paystack Hooks Implementation</button>
      </div>
    );
  };
  return (
    <div>
      
      <PaystackHookExample />
    </div>
    
  )
}

export default PaymentWithPaystack

from react-paystack.

discoverlance-com avatar discoverlance-com commented on September 23, 2024

Can you send your code snippet of the props you are using or passing that's resulting in this error?

from react-paystack.

Handavipul avatar Handavipul commented on September 23, 2024

How can we change text of paystack popup button from "Pay" to "AUTH"

from react-paystack.

kduprey avatar kduprey commented on September 23, 2024

The button is expecting type "callback" for the onSuccess prop however this has been defined as a function with no parameters allowed in the function, resulting in an error with passing a function with parameters when it is called.

from react-paystack.

Onyelaudochukwuka avatar Onyelaudochukwuka commented on September 23, 2024

I was about raising an issue on this
Screen Shot 2022-08-31 at 8 57 46 AM
The callback type wasn't configured correctly

from react-paystack.

kduprey avatar kduprey commented on September 23, 2024

@Onyelaudochukwuka Exactly!! This is what is currently limiting me from migrating to the next major release. It would be great if we could get this resolved.

from react-paystack.

Mublin avatar Mublin commented on September 23, 2024

I had same issues but @chrispydev @iamraphson @Handavipul @discoverlance-com but here is how I handled it with typescript, I remove the function in reference and replaced it with callback which I imported, here is the tweak, I hope it fixes yours too.

code reference: Full repository


import { callback } from `'react-paystack/dist/types';

<PaystackButton {...componentProps as { 
    text: string;
    onSuccess: callback;
    onClose: () => void;
    reference: string;
    email: string;
    amount: number;
    publicKey: string;
}} /> 

You should be good to go with Typescript
I hope it helps

from react-paystack.

chrispydev avatar chrispydev commented on September 23, 2024

Thanks to everyone I fixed this by using a different approach.
And I waiting for ten days to close this issue

from react-paystack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.