garbin / merchantsjs

A framework agnostic, multi-gateway payment processing library for node.js, like Omnipay for php or ActiveMerchants for ruby
MIT License
9 stars 1 forks source link

Custom Gateway #1

Open karneaud opened 7 years ago

karneaud commented 7 years ago

Hi,

I have some familiarity with PHP and Omnipay...how easy is it to add custom payment gateways to your library?

garbin commented 7 years ago

It's very easy.

implements your gateway

const Gateway = require('merchats/lib/gateway')
class YourGateway extends Gateway {
   // define the unique name of your gateway, will be used in merchants.use
   static get name () { return '{{__NAME__}}' }
   // implements purchase method, return a promise, resolve a request object
   async purchase() {
      // access payment config through this.config
   }
   // if the process requires a callback like alipay, implements the callback, return promise, resolve a Response Object
   async callback () {
   }
}

step 2 add your gateway to merchants

const CustomGateway = require('__YOURGATEWAY_PATH__')
merchants.use(new CustomGateway({
  // ... gateway config
}))

step3 use your custom gateway like normal

merchants.using('your gateway name').purchase({
  // ... order info
})

for more info about Request & Response & implements, see https://github.com/garbin/merchantsjs/blob/master/lib/gateways/alipay.js and https://github.com/garbin/merchantsjs/blob/master/lib/gateways/stripe.js

BTW: If your gateway is well-known, and you love to add to merchants for a standard gateway for out-of-box, the PR is welcome:)

Feel free to ask me any questions if you have any trouble within this.

karneaud commented 7 years ago

Great man

The payment gateway is specific to my country so not sure.

PerfectedApp commented 6 years ago

Maybe this thread shouldn't be closed or at least the how-to added to the readme? I'd like to contribute to this project if my team starts building other gateway integrations. Such a shame that there is only Omnipay that's really out there is mature solution.

garbin commented 6 years ago

Good suggestion! I'll reopen this issue and how-to will be added when I have enough time.

PR is welcome! I hope the "HOW-TO" above can give you help. if you have any question, feel free to create issue.

karneaud commented 6 years ago

+1 for this initiative. I hope to also contribute

vanthome commented 5 years ago

Is this initiative dead?

Here are alternatives but they also seem to be dead:

https://github.com/continuous-software/42-cent-base https://github.com/jamescarr/paynode