magpie-js-sdk

1.0.6 • Public • Published

Description

A NodeJS based wrapper that connects to Magpie REST APIs.

Usage

Magpie

To use the sdk, we need to require the Magpie SDK class and create an instance of it.

const Magpie = require('magpie-js-sdk');
 
const isSandbox = false;
const magpie = new Magpie('pk_mypublickey', 'sk_mysecretkey', isSandbox, 'v1.1');
 
// the `magpie` object contains (3) properties
// - magpie.token
// - magpie.charge
// - magpie.customer
 
// each property contains method that is a mapping to Magpie's REST endpoint.

Token

  • Create token using magpie.token.create
magpie.token.create('John Doe', '4242424242424242', '02', '2022', '123')
    .then(response => {
        // response contains object in this shape, { statusCode, body }
        // create token success returns `201` status code
        if (response.statusCode !== 201) {
            // handle error in response here
        }
 
        // handle success scenario
    })
  • Get token info using magpie.token.get
magpie.token.get('tok_123asdfa034jasdf')
    .then(response => {
        // response contains object in this shape, { statusCode, body }
        if (response.statusCode !== 200) {
            // handle error in response here
        }
        // handle success scenario here
    })

Customer

  • Create customer: magpie.customer.create
const email = 'john.doe@gmail.com';
const description = 'Developer';
magpie.customer.create(email, description)
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Get customer: magpie.customer.get
magpie.customer.get('cus_1adlkfjas03asdf')
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Add/update customer payment source: magpie.customer.update
magpie.customer.update('cus_1adlkfjas03asdf', 'tok_asdfas39234asdf')
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Delete customer payment source: magpie.customer.deleteSource
magpie.customer.deleteSource('cus_1adlkfjas03asdf', 'card_asdfas3asdfas3')
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Delete customer: magpie.customer.delete
magpie.customer.delete('cus_1adlkfjas03asdf')
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });

Charge

  • Create charge: magpie.charge.create
const amount = 5000;
const currency = "PHP";
const source = 'tok_asldfjalsdfja98a7sfa';
const description = "Test create charge";
const statementDescriptor = "Test statement";
const capture = true;
magpie.charge.create(
    amount,
    currency,
    source,
    description,
    statementDescriptor,
    capture
  )
    .then(response => {
        // create charge success returns `201` status code
        if (response.statusCode !== 201) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Get charge: magpie.charge.get
magpie.charge.get('ch_awdkfjalsdjf30234a')
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Capture charge: magpie.charge.capture
magpie.charge.capture('ch_awdkfjalsdjf30234a', 5000)
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Void charge: magpie.charge.void
magpie.charge.void('ch_awdkfjalsdjf30234a')
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });
  • Refund charge: magpie.charge.refund
magpie.charge.refund('ch_awdkfjalsdjf30234a', 5000)
    .then(response => {
        if (response.statusCode !== 200) {
            // handle error scenario here
        }
        // handle success scenario here
    });

If you have suggestions or comments, kindly email me markronquillo23@gmail.com

Readme

Keywords

Package Sidebar

Install

npm i magpie-js-sdk

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

15.4 kB

Total Files

9

Last publish

Collaborators

  • markronquillo