+++ /dev/null
-const https = require('https');
-const get_oauth = config => {
- return new Promise(resolve => {
-
- const data = 'grant_type=client_credentials';
-
- const options = {
- hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
- port: 443,
- path: '/v1/oauth2/token',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': data.length,
- 'Authorization': 'Basic ' + Buffer.from((config.environment === 'sandbox' ? config.sandbox_client_id : config.production_client_id) + ':' + (config.environment === 'sandbox' ? config.sandbox_secret : config.production_secret)).toString('base64')
- }
- }
- const my_callback = function(res){
-
- let str='';
-
- res.on('data',function(chunk){
- str+=chunk;
- });
-
- res.on('end',function(){
- obj=JSON.parse(str);
- resolve(obj);
- });
- }
- let request = https.request(options, my_callback);
- request.write(data);
- request.end();
-
- });
-};
-const get_access_token = config => {
- return new Promise(resolve => {
- get_oauth(config).then((response) => {
- resolve(response.access_token);
- });
- });
-};
-const create_order = (config, item_obj) => {
- return new Promise(resolve => {
- get_access_token(config).then((access_token) => {
-
- const options = {
- hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
- port: 443,
- path: '/v2/checkout/orders',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + access_token
- }
- }
- const my_callback = function(res){
-
- let str='';
-
- res.on('data',function(chunk){
- str+=chunk;
- });
-
- res.on('end',function(){
- obj=JSON.parse(str);
- resolve(obj);
- });
- }
- let request = https.request(options,my_callback);
- request.write(JSON.stringify(item_obj));
- request.end();
-
- });
-
- });
-};
-const get_order_details = (config, order_id) => {
- return new Promise(resolve => {
- get_access_token(config).then((access_token) => {
-
- const options = {
- hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
- port: 443,
- path: '/v2/checkout/orders/' + order_id,
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + access_token
- }
- }
- const my_callback = function(res){
-
- let str='';
-
- res.on('data',function(chunk){
- str+=chunk;
- });
-
- res.on('end',function(){
- obj=JSON.parse(str);
- resolve(obj);
- });
- }
- let request = https.request(options,my_callback);
- request.end();
-
- });
-
- });
-};
-const patch_order_details = (config, new_order_details) => {
- return new Promise((resolve, reject) => {
- get_access_token(config).then((access_token) => {
- patch_details = new_order_details.patch_details;
- order_id = new_order_details.order_id;
- const options = {
- hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
- port: 443,
- path: '/v2/checkout/orders/' + order_id,
- method: 'PATCH',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + access_token
- }
- }
- let request = https.request(options, function (response) {
- resolve(response.statusCode);
- });
- request.write(JSON.stringify(patch_details));
- request.end();
- });
-});
-
-};
-const capture_order = (config, order_id) => {
- return new Promise(resolve => {
- get_access_token(config).then((access_token) => {
- const options = {
- hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
- port: 443,
- path: '/v2/checkout/orders/' + order_id + '/capture',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + access_token,
- 'return': 'representation',
- 'PayPal-Partner-Attribution-Id': 'PP-DemoPortal-Checkout-NodeJS-SDK'
- }
- }
- const my_callback = function(res){
- let str='';
- res.on('data',function(chunk){
- str+=chunk;
- });
- res.on('end',function(){
- obj=JSON.parse(str);
- resolve(obj);
- });
- }
- let request = https.request(options,my_callback);
- request.end();
- });
- });
-};
-
-return {
- get_access_token: get_access_token,
- get_oauth: get_oauth,
- create_order: create_order,
- get_order_details: get_order_details,
- patch_order_details: patch_order_details,
- capture_order: capture_order
-};
--- /dev/null
+let https = require('https');
+
+return async (config, order_id) => {
+ let get_access_token = await _require('get_access_token.jst');
+
+ return new Promise(resolve => {
+ get_access_token(config).then((access_token) => {
+ const options = {
+ hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
+ port: 443,
+ path: '/v2/checkout/orders/' + order_id + '/capture',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + access_token,
+ 'return': 'representation',
+ 'PayPal-Partner-Attribution-Id': 'PP-DemoPortal-Checkout-NodeJS-SDK'
+ }
+ }
+ const my_callback = function(res){
+ let str='';
+ res.on('data',function(chunk){
+ str+=chunk;
+ });
+ res.on('end',function(){
+ obj=JSON.parse(str);
+ resolve(obj);
+ });
+ }
+ let request = https.request(options,my_callback);
+ request.end();
+ });
+ });
+};
--- /dev/null
+let https = require('https');
+
+return async (config, item_obj) => {
+ let get_access_token = await _require('get_access_token.jst');
+
+ return new Promise(resolve => {
+ get_access_token(config).then((access_token) => {
+
+ const options = {
+ hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
+ port: 443,
+ path: '/v2/checkout/orders',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + access_token
+ }
+ }
+ const my_callback = function(res){
+
+ let str='';
+
+ res.on('data',function(chunk){
+ str+=chunk;
+ });
+
+ res.on('end',function(){
+ obj=JSON.parse(str);
+ resolve(obj);
+ });
+ }
+ let request = https.request(options,my_callback);
+ request.write(JSON.stringify(item_obj));
+ request.end();
+
+ });
+
+ });
+};
--- /dev/null
+let https = require('https');
+
+return async config => {
+ let get_oauth = await _require('get_oauth.jst');
+
+ return new Promise(resolve => {
+ get_oauth(config).then((response) => {
+ resolve(response.access_token);
+ });
+ });
+};
+
--- /dev/null
+let https = require('https');
+
+return async config => {
+ return new Promise(resolve => {
+
+ const data = 'grant_type=client_credentials';
+
+ const options = {
+ hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
+ port: 443,
+ path: '/v1/oauth2/token',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Content-Length': data.length,
+ 'Authorization': 'Basic ' + Buffer.from((config.environment === 'sandbox' ? config.sandbox_client_id : config.production_client_id) + ':' + (config.environment === 'sandbox' ? config.sandbox_secret : config.production_secret)).toString('base64')
+ }
+ }
+ const my_callback = function(res){
+
+ let str='';
+
+ res.on('data',function(chunk){
+ str+=chunk;
+ });
+
+ res.on('end',function(){
+ obj=JSON.parse(str);
+ resolve(obj);
+ });
+ }
+ let request = https.request(options, my_callback);
+ request.write(data);
+ request.end();
+
+ });
+};
--- /dev/null
+let https = require('https');
+
+return async (config, order_id) => {
+ let get_access_token = await _require('get_access_token.jst');
+
+ return new Promise(resolve => {
+ get_access_token(config).then((access_token) => {
+
+ const options = {
+ hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
+ port: 443,
+ path: '/v2/checkout/orders/' + order_id,
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + access_token
+ }
+ }
+ const my_callback = function(res){
+
+ let str='';
+
+ res.on('data',function(chunk){
+ str+=chunk;
+ });
+
+ res.on('end',function(){
+ obj=JSON.parse(str);
+ resolve(obj);
+ });
+ }
+ let request = https.request(options,my_callback);
+ request.end();
+
+ });
+
+ });
+};
--- /dev/null
+let https = require('https');
+
+return async (config, new_order_details) => {
+ let get_access_token = await _require('get_access_token.jst');
+
+ return new Promise((resolve, reject) => {
+ get_access_token(config).then((access_token) => {
+ patch_details = new_order_details.patch_details;
+ order_id = new_order_details.order_id;
+ const options = {
+ hostname: 'api.' + (config.environment === 'sandbox' ? 'sandbox.' : '') + 'paypal.com',
+ port: 443,
+ path: '/v2/checkout/orders/' + order_id,
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + access_token
+ }
+ }
+ let request = https.request(options, function (response) {
+ resolve(response.statusCode);
+ });
+ request.write(JSON.stringify(patch_details));
+ request.end();
+ });
+});
+
+};
let cookie = require('cookie')
return async env => {
- let basic_functions = await _require('/_library/basic_functions.jst')
+ let capture_order = await _require('/_library/capture_order.jst')
let config = await env.site.get_json('/_config/config.json')
let cookies = cookie.parse(env.request.headers.cookie || '')
- let response = await basic_functions.capture_order(config, cookies.order_id)
+ let response = await capture_order(config, cookies.order_id)
console.log('capture_order()', response)
env.site.serve(
let XDate = require('xdate')
return async env => {
- let basic_functions = await _require('/_library/basic_functions.jst')
let config = await env.site.get_json('/_config/config.json')
+ let create_order = await _require('/_library/create_order.jst')
let random_number = await _require('/_library/random_number.jst')
let response = null
}
}
console.log('item_obj', item_obj)
- response = await basic_functions.create_order(config, item_obj)
+ response = await create_order(config, item_obj)
console.log('create_order()', response)
//sess.order_id = response.id
let cookie = require('cookie')
return async env => {
- let basic_functions = await _require('/_library/basic_functions.jst')
let config = await env.site.get_json('/_config/config.json')
+ let get_order_details = await _require('/_library/get_order_details.jst')
let cookies = cookie.parse(env.request.headers.cookie || '')
- let response =
- await basic_functions.get_order_details(config, cookies.order_id)
+ let response = await get_order_details(config, cookies.order_id)
console.log('get_order_details()', response)
env.site.serve(
let XDate = require('xdate')
return async env => {
- let basic_functions = await _require('/_library/basic_functions.jst')
let config = await env.site.get_json('/_config/config.json')
+ let patch_order_details = await _require('/_library/patch_order_details.jst')
let random_number = await _require('/_library/random_number.jst')
let response = null
"order_id": cookies.order_id
}
response = {
- http_code:
- await basic_functions.patch_order_details(config, new_order_details)
+ http_code: await patch_order_details(config, new_order_details)
}
console.log('patch_order_details()', response)
}