Created
January 21, 2018 23:13
-
-
Save cannap/7ecebef3bab75857e8118594851485b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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