Giter VIP home page Giter VIP logo

Comments (1)

mkharibalaji avatar mkharibalaji commented on September 9, 2024

Hi @dmitry-blackwave ,
The below fix worked for me after editing index.js
import {NativeEventEmitter, NativeModules} from 'react-native';

const Adyen = NativeModules.Adyen || NativeModules.AdyenReactNative;
const events = new NativeEventEmitter(Adyen);
let onRequestPaymentSessionListener;
let onPaymentResultListener;
let onErrorListener;
let onSelectPaymentMethodListener;

export default {
/**
* The Quick integration of the SDK provides UI components for payment method selection, entering payment method details (credit card entry form, iDEAL issuer selection, etc.).
* @returns {}
/
startPayment() {
return Adyen.startPayment();
},
/
*
* Generating StartPaymentParameters
*
* @param {String} encodedToken
*
* @returns {
}
*/
confirmPayment(encodedToken) {
this._validateParam(encodedToken, 'confirmPayment', 'string');

    return Adyen.confirmPayment(encodedToken);
},
/**
 * @param {String} encodedToken
 * @returns {*}
 */
createPaymentSession(encodedToken) {
    this._validateParam(encodedToken, 'createPaymentSession', 'string');

    return Adyen.createPaymentSession(encodedToken);
},
/**
 * Starting payment process.
 * @returns {*}
 */
initPayment() {
    return Adyen.initPayment();
},
/**
 * @callback mOnRequestPaymentSession
 * @param {String} token
 * @param {String} returnUrl
 */
/**
 * Native event. Calling when CheckoutController calls delegate in the native call.
 * It calling with token and returnUrl (can be empty, no worries)
 * @param {mOnRequestPaymentSession} mOnRequestPaymentSession
 */
onRequestPaymentSession(mOnRequestPaymentSession) {
    this._validateParam(mOnRequestPaymentSession, 'onRequestPaymentSession', 'function');
    onRequestPaymentSessionListener = events.addListener('onRequestPaymentSession', (response) => {
        mOnRequestPaymentSession(response['token'], response['returnUrl']);
    });
},
/**
 * @callback mOnPaymentResult
 * @param {Number} code
 * @param {String} payload
 */
/**
 * After successfully payment, added payload data for confirmation payments
 * @param {mOnPaymentResult} mOnPaymentResult
 */
onPaymentResult(mOnPaymentResult) {
    this._validateParam(mOnPaymentResult, 'onPaymentResult', 'function');
    onPaymentResultListener = events.addListener('onPaymentResult', (response) => {
        mOnPaymentResult(response['code'], response['payload']);
    });
},
/**
 * @callback mOnError
 * @param {Number} code
 * @param {String} message
 */
/**
 * If payment was cancelled or something else. Calling instead of onPaymentResult event.
 * @param {mOnError} mOnError
 */
onError(mOnError) {
    this._validateParam(mOnError, 'onError', 'function');
    onErrorListener = events.addListener('onError', (response) => {
        mOnError(response['code'], response['message']);
    });
},
/**
 * @callback mOnSelectPaymentMethod
 * @param {Array<>} preferred
 * @param {Array<>} other
 * @param {number} count
 */
/**
 * //TODO custom integration
 * @param {mOnSelectPaymentMethod} mOnSelectPaymentMethod
 */
onSelectPaymentMethod(mOnSelectPaymentMethod) {
    this._validateParam(mOnSelectPaymentMethod, 'onSelectPaymentMethod', 'function');
    **onSelectPaymentMethodListener =** events.addListener('onSelectPaymentMethodListener;', (response) => {
        mOnSelectPaymentMethod(response['preferred'], response['other'], response['count']);
    });
},
/**
 * @param {*} param
 * @param {String} methodName
 * @param {String} requiredType
 * @private
 */
_validateParam(param, methodName, requiredType) {
    if (typeof param !== requiredType) {
        throw new Error(`Error: Adyen.${methodName}() requires a ${requiredType === 'function' ? 'callback function' : requiredType} but got a ${typeof param}`);
    }
},
events,
**removeListeners(){
    if(null != onRequestPaymentSessionListener)   
        onRequestPaymentSessionListener.remove();
    if(null != onPaymentResultListener)
        onPaymentResultListener.remove();
    if(null != onErrorListener)
        onErrorListener.remove();
    if(null != onSelectPaymentMethodListener)
        onSelectPaymentMethodListener.remove();
}**

};

from adyen-react-native.

Related Issues (18)

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.