Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit 44afb85

Browse files
author
Chirag Patel
committed
validity days update to month
1 parent 81b12e2 commit 44afb85

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

service/src/services/checkout/checkout.class.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ class Service {
6262
}
6363
}
6464

65-
var payObj = async( function (data, price) {
65+
var payObj = async function (data, price) {
6666
var sObj = {
6767
gateway:'stripe',
68-
amount : parseInt(price),
68+
amount : parseFloat(price),
6969
currency:'usd',
7070
cardNumber: data.payDetail.cardNumber,
7171
expMonth: data.payDetail.expiryMM,
7272
expYear: data.payDetail.expiryYY,
7373
cvc: data.payDetail.cvCode,
74-
description:'this is desc',
74+
description:'payment for subscription plan subscribe',
7575
isCustomer:false,
7676
metadata: {
7777
id: data.sub_id
7878
}
7979
}
8080
return sObj
81-
})
81+
}
8282

83-
var getThisSubscription = async(function (id, app) {
83+
var getThisSubscription = async function (id, app) {
8484
// var res = await (axios.get(baseURL + '/subscription-plans/' + id))
8585
return app.service('subscription-plans').get(id)
8686
.then(res => {
@@ -89,12 +89,19 @@ var getThisSubscription = async(function (id, app) {
8989
.catch(err => {
9090
console.log('Error in checkout at getThisSubscription:', err)
9191
})
92-
})
92+
}
9393

9494
var createFunction = async (function(data,params, app) {
9595
// console.log("+++++++++++ params",params.query.authorization)
9696
var thisSubscription = await (getThisSubscription(data.sub_id, app))
97-
// console.log('thisSubscription', thisSubscription)
97+
console.log('thisSubscription', thisSubscription)
98+
if(thisSubscription === undefined || thisSubscription === null) {
99+
return {error: 'please select valid subscription plan'}
100+
}
101+
if(thisSubscription.hasOwnProperty('status') && thisSubscription.status === false) {
102+
return {error: 'please select valid subscription plan'}
103+
}
104+
98105
var paymentObj = await (payObj(data, thisSubscription.price))
99106
var config = {
100107
headers: {
@@ -113,7 +120,7 @@ var createFunction = async (function(data,params, app) {
113120
return {error: err}
114121
}))
115122
if(checkout_res.hasOwnProperty('statusCode')) {
116-
return {error: res.data.message}
123+
return {error: checkout_res.message}
117124
} else {
118125
console.log('payment Successfully Done!')
119126
let userDetail = await (getUserPackage(config.headers.authorization))
@@ -194,13 +201,13 @@ var createFunction = async (function(data,params, app) {
194201
let makePackageObj = async (function (subData, trans_id, subscribed, userDetail) {
195202
var exdate
196203
if (subscribed != null) {
197-
if(moment(subscribed.expiredOn).diff(moment().format(), 'days') <= 0) {
198-
exdate = moment().add(subData.validity, 'days').format()
204+
if(moment(subscribed.expiredOn).diff(moment().format(), 'months') <= 0) {
205+
exdate = moment().add(subData.validity, 'months').format()
199206
} else {
200-
exdate = moment(subscribed.expiredOn).add(subData.validity, 'days').format()
207+
exdate = moment(subscribed.expiredOn).add(subData.validity, 'months').format()
201208
}
202209
} else {
203-
exdate = moment().add(subData.validity, 'days').format()
210+
exdate = moment().add(subData.validity, 'months').format()
204211
}
205212
// console.log("exdate :",exdate)
206213
var detail = {}

0 commit comments

Comments
 (0)