UNPKG

payrex-node

Version:
68 lines (61 loc) 1.97 kB
const payrex = require('payrex-node')( 'sk_live_znE26cM4ZbZP3mfTLeZsnw7EceWHKiPN' ); const RequestInvalidError = require('./src/errors/RequestInvalidError'); const AuthenticationInvalidError = require('./src/errors/AuthenticationInvalidError'); const ResourceNotFoundError = require('./src/errors/ResourceNotFoundError'); // try { // const paymentIntent = await payrex.paymentIntents.create({ amount: 10000 }); // } catch (error) { // console.log('caught error!') // if (error instanceof ResourceNotFoundError) { // // handle error if a resource does not exist. // } else if (error instanceof AuthenticationInvalidError) { // // handle authentication error // } else if (error instanceof RequestInvalidError) { // console.log('handle error if there\'s validation error'); // error.errors.forEach((e) => { // console.log(e.code); // console.log(e.detail); // }); // } // } (async () => { try { const paymentIntent = await payrex.paymentIntents.create({ amount: 10000 }); } catch (error) { console.log('caught error!'); console.log(error.name); if (error.name === 'ResourceNotFoundError') { // handle error if a resource does not exist. } else if (error.name === 'AuthenticationInvalidError') { // handle authentication error } else if (error.name === 'RequestInvalidError') { console.log("handle error if there's validation error"); error.errors.forEach((e) => { console.log(e.code); console.log(e.detail); }); } } })(); const refund = await payrex.refunds.update( 're_xPy5nb7p6R7jG4ZPEJu5WvVCb8Lz31qx', { metadata: { 'some_key3': 'some_val3' } } ) const billingStatement = await payrex.billingStatements.create( { currency: 'PHP', customer_id: 'cus_BcArwt1hUhBB8HTdbsWxeDavsv5Jm37L', payment_settings: { payment_methods: [ 'card' ] }, setup_future_usage: 'on_session' } )