Skip to content

Instantly share code, notes, and snippets.

@cannap
Created January 21, 2018 23:13
Show Gist options
  • Select an option

  • Save cannap/7ecebef3bab75857e8118594851485b3 to your computer and use it in GitHub Desktop.

Select an option

Save cannap/7ecebef3bab75857e8118594851485b3 to your computer and use it in GitHub Desktop.
const Gateway = require('../../Gateway')
const paypal = require('paypal-rest-sdk')
module.exports = class PayPal extends Gateway {
static get name () {
return 'paypal'
}
constructor (config) {
super()
this.items = []
const defaults = {
mode: 'sandbox',
client_id:
'xxxx', // your paypal application client id
client_secret:
'xxxx' // your paypal application secret id
}
const env = new paypal.SandboxEnvironment(
defaults.client_id,
defaults.client_secret
)
this.client = new paypal.PayPalHttpClient(env)
}
charge (order) {
let body = {
intent: 'sale',
payer: {
payment_method: 'paypal'
},
transactions: [
{
amount: {
total: '10',
currency: 'USD'
}
}
],
redirect_urls: {
cancel_url: 'http://paypal.com/cancel',
return_url: 'http://paypal.com/return'
}
}
let request = new paypal.PaymentCreateRequest()
request.requestBody(body)
return this.client.execute(request)
}
addItem (item) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment