@questwork/q-store-model 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.cjs +645 -635
- package/dist/index.min.js +645 -635
- package/dist/q-store-model.min.js +6961 -0
- package/package.json +9 -8
package/dist/index.min.js
CHANGED
|
@@ -2400,8 +2400,8 @@ class Status {
|
|
|
2400
2400
|
return this.assigned !== null
|
|
2401
2401
|
}
|
|
2402
2402
|
get isCancelled() {
|
|
2403
|
-
return this.lastStatus === 'cancelled'
|
|
2404
|
-
|
|
2403
|
+
// return this.lastStatus === 'cancelled'
|
|
2404
|
+
return this.cancelled !== null
|
|
2405
2405
|
}
|
|
2406
2406
|
get isCompleted() {
|
|
2407
2407
|
return this.completed !== null
|
|
@@ -3806,68 +3806,63 @@ class Issuer {
|
|
|
3806
3806
|
|
|
3807
3807
|
|
|
3808
3808
|
|
|
3809
|
-
;// ./lib/models/
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3809
|
+
;// ./lib/models/walletItem/walletItem.js
|
|
3813
3810
|
|
|
3814
3811
|
|
|
3815
3812
|
|
|
3816
3813
|
|
|
3814
|
+
// import { Transaction } from '../transaction/index.js'
|
|
3817
3815
|
|
|
3818
|
-
const
|
|
3816
|
+
const walletItem_updateAllowedProps = [
|
|
3819
3817
|
'active',
|
|
3820
|
-
'checkoutDateTime',
|
|
3821
3818
|
'deleted',
|
|
3822
|
-
'
|
|
3823
|
-
'
|
|
3824
|
-
'
|
|
3825
|
-
'metadata',
|
|
3819
|
+
'owner',
|
|
3820
|
+
'purchaseOptions',
|
|
3821
|
+
'qty',
|
|
3826
3822
|
'remarks',
|
|
3827
|
-
'
|
|
3828
|
-
'status'
|
|
3823
|
+
'status',
|
|
3829
3824
|
]
|
|
3830
3825
|
|
|
3831
|
-
class
|
|
3832
|
-
constructor(options) {
|
|
3826
|
+
class WalletItem {
|
|
3827
|
+
constructor(options = {}) {
|
|
3833
3828
|
options = options || {}
|
|
3834
|
-
const {
|
|
3835
|
-
this.
|
|
3836
|
-
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
3837
|
-
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
3838
|
-
this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
|
|
3829
|
+
const { _Product, _Status } = options._constructor || {}
|
|
3830
|
+
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3839
3831
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3832
|
+
// this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
3833
|
+
|
|
3834
|
+
this._product = options._product
|
|
3835
|
+
this._tenant = options._tenant
|
|
3836
|
+
this._transaction = options._transaction
|
|
3840
3837
|
|
|
3841
|
-
this._cart = options._cart
|
|
3842
|
-
this._invoiceLines = options._invoiceLines
|
|
3843
|
-
|
|
3844
3838
|
const id = options._id || options.id
|
|
3845
|
-
this.id =
|
|
3846
|
-
this._type = options._type || 'Invoice'
|
|
3839
|
+
this.id = walletItem_setId(id)
|
|
3847
3840
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3848
|
-
this.amount = this._Amount.init(options.amount)
|
|
3849
|
-
this.cartCode = options.cartCode
|
|
3850
|
-
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
3851
3841
|
this.created = options.created || (new Date()).valueOf()
|
|
3852
3842
|
this.creator = options.creator
|
|
3853
3843
|
this.deleted = options.deleted || false
|
|
3854
|
-
this.description = options.description
|
|
3855
|
-
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
3856
|
-
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
3857
|
-
this.invoiceNumber = options.invoiceNumber
|
|
3858
|
-
this.issuer = this._Issuer.init(options.issuer)
|
|
3859
3844
|
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3860
3845
|
this.modified = options.modified || (new Date()).valueOf()
|
|
3861
3846
|
this.owner = options.owner
|
|
3847
|
+
this.productCode = options.productCode
|
|
3848
|
+
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3849
|
+
this.qty = options.qty || 1
|
|
3862
3850
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3863
|
-
this.revisionNumber = options.revisionNumber || 1
|
|
3864
3851
|
this.status = this._Status.init(options.status)
|
|
3865
3852
|
this.tenantCode = options.tenantCode
|
|
3853
|
+
this.transactionCode = options.transactionCode
|
|
3854
|
+
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
3866
3855
|
}
|
|
3867
3856
|
|
|
3857
|
+
// Class methods
|
|
3868
3858
|
static dummyData() {
|
|
3869
3859
|
return {
|
|
3870
|
-
|
|
3860
|
+
// companyCode: 'demo',
|
|
3861
|
+
productCode: '5cd4f5430c2b874ad7ed8cfd',
|
|
3862
|
+
qty: 1,
|
|
3863
|
+
status: Status.dummyData(),
|
|
3864
|
+
tenantCode: 'tenantCode',
|
|
3865
|
+
transactionCode: 'transactionCode'
|
|
3871
3866
|
}
|
|
3872
3867
|
}
|
|
3873
3868
|
static init(options = {}) {
|
|
@@ -3887,126 +3882,178 @@ class Invoice {
|
|
|
3887
3882
|
return this.initFromArray(arr).filter((i) => i)
|
|
3888
3883
|
}
|
|
3889
3884
|
static get _classname() {
|
|
3890
|
-
return '
|
|
3885
|
+
return 'WalletItem'
|
|
3891
3886
|
}
|
|
3892
3887
|
static get _superclass() {
|
|
3893
|
-
return '
|
|
3888
|
+
return 'WalletItem'
|
|
3894
3889
|
}
|
|
3895
3890
|
|
|
3891
|
+
// getters
|
|
3896
3892
|
get isValid() {
|
|
3897
|
-
return !!this.tenantCode
|
|
3893
|
+
return !!this.tenantCode && !!this.productCode
|
|
3898
3894
|
}
|
|
3899
|
-
get
|
|
3900
|
-
return this.
|
|
3895
|
+
get isAssigned() {
|
|
3896
|
+
return this.status.isAssigned
|
|
3901
3897
|
}
|
|
3902
|
-
get
|
|
3903
|
-
return this.
|
|
3898
|
+
get isCancelled() {
|
|
3899
|
+
return this.status.isCancelled
|
|
3904
3900
|
}
|
|
3905
|
-
get
|
|
3906
|
-
return
|
|
3907
|
-
return i.merchandise
|
|
3908
|
-
}).filter((i) => i)
|
|
3901
|
+
get isCompleted() {
|
|
3902
|
+
return this.status.isCompleted
|
|
3909
3903
|
}
|
|
3910
|
-
get
|
|
3911
|
-
return this.
|
|
3912
|
-
const found = acc.find((a) => {
|
|
3913
|
-
return a.merchandiseCode === m.merchandiseCode
|
|
3914
|
-
})
|
|
3915
|
-
if (found) {
|
|
3916
|
-
found.qty += 1
|
|
3917
|
-
} else {
|
|
3918
|
-
acc.push({
|
|
3919
|
-
...m.summary,
|
|
3920
|
-
qty: 1
|
|
3921
|
-
})
|
|
3922
|
-
}
|
|
3923
|
-
return acc
|
|
3924
|
-
}, [])
|
|
3904
|
+
get isConfirmed() {
|
|
3905
|
+
return this.status.isConfirmed
|
|
3925
3906
|
}
|
|
3926
|
-
get
|
|
3927
|
-
return
|
|
3928
|
-
if (m.products) {
|
|
3929
|
-
acc = acc.concat(m.products)
|
|
3930
|
-
}
|
|
3931
|
-
return acc
|
|
3932
|
-
}, [])
|
|
3907
|
+
get isDelivered() {
|
|
3908
|
+
return this.status.isDelivered
|
|
3933
3909
|
}
|
|
3934
|
-
get
|
|
3935
|
-
return
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
qty: 1
|
|
3945
|
-
})
|
|
3946
|
-
}
|
|
3947
|
-
return acc
|
|
3948
|
-
}, [])
|
|
3910
|
+
get isOwned() {
|
|
3911
|
+
return (
|
|
3912
|
+
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
3913
|
+
&& (
|
|
3914
|
+
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3915
|
+
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
3916
|
+
|| (this.isRedeemed && !this.isAssigned && !this.isConfirmed)
|
|
3917
|
+
|| (this.isAssigned && this.isConfirmed)
|
|
3918
|
+
)
|
|
3919
|
+
)
|
|
3949
3920
|
}
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3921
|
+
get isPaid() {
|
|
3922
|
+
return this.status.isPaid
|
|
3923
|
+
}
|
|
3924
|
+
get isPending() {
|
|
3925
|
+
return this.status.isPending
|
|
3926
|
+
}
|
|
3927
|
+
get isRedeemed() {
|
|
3928
|
+
return this.status.redeemed
|
|
3929
|
+
}
|
|
3930
|
+
get isRefunded() {
|
|
3931
|
+
return this.status.isRefunded
|
|
3932
|
+
}
|
|
3933
|
+
get isRejected() {
|
|
3934
|
+
return this.status.rejected
|
|
3935
|
+
}
|
|
3936
|
+
get isShared() {
|
|
3937
|
+
return this.status.shared
|
|
3938
|
+
}
|
|
3939
|
+
get isSubmitted() {
|
|
3940
|
+
return this.status.isSubmitted
|
|
3941
|
+
}
|
|
3942
|
+
get isUsed() {
|
|
3943
|
+
return this.status.isUsed
|
|
3944
|
+
}
|
|
3945
|
+
get isWaived() {
|
|
3946
|
+
return this.status.isWaived
|
|
3947
|
+
}
|
|
3948
|
+
get product() {
|
|
3949
|
+
return this._Product.init(this._product)
|
|
3950
|
+
}
|
|
3951
|
+
get tenant() {
|
|
3952
|
+
return this._tenant
|
|
3953
|
+
}
|
|
3954
|
+
// get transaction() {
|
|
3955
|
+
// return this._Transaction.init(this._transaction)
|
|
3956
|
+
// }
|
|
3957
|
+
get usedTimestamp() {
|
|
3958
|
+
return this.status.used
|
|
3953
3959
|
}
|
|
3954
3960
|
|
|
3955
3961
|
// instance methods
|
|
3956
|
-
|
|
3957
|
-
|
|
3962
|
+
formatFlexcel() {
|
|
3963
|
+
const obj = {
|
|
3964
|
+
...this,
|
|
3965
|
+
...this.status,
|
|
3966
|
+
used: this.isUsed,
|
|
3967
|
+
productName: this.product && this.product.name ? this.product.name : ''
|
|
3968
|
+
}
|
|
3969
|
+
return obj
|
|
3958
3970
|
}
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3971
|
+
formatOutput({ format }) {
|
|
3972
|
+
switch (format) {
|
|
3973
|
+
case 'flexcel':
|
|
3974
|
+
return this.formatFlexcel()
|
|
3975
|
+
default:
|
|
3976
|
+
return this
|
|
3977
|
+
}
|
|
3962
3978
|
}
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3979
|
+
isSameOwner(userId) {
|
|
3980
|
+
return userId
|
|
3981
|
+
? (userId === this.owner)
|
|
3982
|
+
: false
|
|
3966
3983
|
}
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
this.revisionNumber += 1
|
|
3984
|
+
setAssigned(value) {
|
|
3985
|
+
this.status.setAssigned(value)
|
|
3970
3986
|
return this
|
|
3971
3987
|
}
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
return this
|
|
3988
|
+
setConfirmed(value) {
|
|
3989
|
+
this.status.setConfirmed(value)
|
|
3990
|
+
return this
|
|
3975
3991
|
}
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
if (typeof timestamp === 'number') {
|
|
3979
|
-
this.checkoutDateTime = timestamp
|
|
3980
|
-
}
|
|
3992
|
+
setDelivered(value) {
|
|
3993
|
+
this.status.setDelivered(value)
|
|
3981
3994
|
return this
|
|
3982
3995
|
}
|
|
3983
|
-
|
|
3984
3996
|
setModified() {
|
|
3985
3997
|
this.modified = (new Date()).valueOf()
|
|
3986
3998
|
return this
|
|
3987
3999
|
}
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
this
|
|
3991
|
-
|
|
4000
|
+
setPaid() {
|
|
4001
|
+
this.status.setPaid()
|
|
4002
|
+
return this
|
|
4003
|
+
}
|
|
4004
|
+
setPaidTimestamp(paidTimestamp) {
|
|
4005
|
+
this.status.setPaid(paidTimestamp)
|
|
4006
|
+
// this.statusTimestamp.setPaid(paidTimestamp)
|
|
4007
|
+
return this
|
|
4008
|
+
}
|
|
4009
|
+
setPending() {
|
|
4010
|
+
this.status.setPending()
|
|
4011
|
+
return this
|
|
4012
|
+
}
|
|
4013
|
+
setRedeemed() {
|
|
4014
|
+
this.status.setRedeemed()
|
|
4015
|
+
return this
|
|
4016
|
+
}
|
|
4017
|
+
setRejected() {
|
|
4018
|
+
this.status.setRejected()
|
|
4019
|
+
return this
|
|
4020
|
+
}
|
|
4021
|
+
setShared() {
|
|
4022
|
+
this.status.setShared()
|
|
4023
|
+
return this
|
|
4024
|
+
}
|
|
4025
|
+
setUsedTimestamp() {
|
|
4026
|
+
this.status.setUsed()
|
|
4027
|
+
// this.statusTimestamp.setUsed()
|
|
4028
|
+
return this
|
|
3992
4029
|
}
|
|
3993
|
-
|
|
3994
4030
|
setWaived() {
|
|
3995
4031
|
this.status.setWaived()
|
|
3996
|
-
return this
|
|
4032
|
+
return this
|
|
3997
4033
|
}
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4034
|
+
// toTicket() {
|
|
4035
|
+
// return {
|
|
4036
|
+
// delivered: this.status.delivered,
|
|
4037
|
+
// eventRegistrationCode: this.eventRegistrationCode,
|
|
4038
|
+
// eventShortCode: this.eventShortCode,
|
|
4039
|
+
// name: this.product.name,
|
|
4040
|
+
// printLayoutCodes: this.product.printLayoutCodes,
|
|
4041
|
+
// productCategories: this.product.productCategories,
|
|
4042
|
+
// productCode: this.productCode,
|
|
4043
|
+
// settled: this.status.settled,
|
|
4044
|
+
// takenTime: this.statusTimestamp.delivered,
|
|
4045
|
+
// tenantCode: this.tenantCode,
|
|
4046
|
+
// waived: this.status.waived,
|
|
4047
|
+
// walletItemCode: this.walletItemCode
|
|
4048
|
+
// }
|
|
4049
|
+
// }
|
|
4050
|
+
update(update) {
|
|
4051
|
+
Object.keys(update).forEach((key) => {
|
|
4052
|
+
if (walletItem_updateAllowedProps.includes(key)) {
|
|
4053
|
+
if (key === 'metadata') {
|
|
4007
4054
|
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4008
|
-
} else if (key === '
|
|
4009
|
-
this[key] =
|
|
4055
|
+
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
4056
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4010
4057
|
} else if (key === 'status') {
|
|
4011
4058
|
this[key] = this._Status.init(update[key])
|
|
4012
4059
|
} else {
|
|
@@ -4018,162 +4065,14 @@ class Invoice {
|
|
|
4018
4065
|
}
|
|
4019
4066
|
}
|
|
4020
4067
|
|
|
4021
|
-
function
|
|
4022
|
-
const copyOptions = options || {}
|
|
4023
|
-
if (copyOptions[key]) {
|
|
4024
|
-
return copyOptions[key]
|
|
4025
|
-
}
|
|
4026
|
-
return stringHelper.setCode()
|
|
4027
|
-
}
|
|
4028
|
-
|
|
4029
|
-
function invoice_setId(id) {
|
|
4068
|
+
function walletItem_setId(id) {
|
|
4030
4069
|
if (id && typeof id.toString === 'function') {
|
|
4031
4070
|
return id.toString()
|
|
4032
4071
|
}
|
|
4033
4072
|
return id
|
|
4034
4073
|
}
|
|
4035
4074
|
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
;// ./lib/models/invoice/invoiceRepo.js
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
class InvoiceRepo extends q_utilities_namespaceObject.Repo {
|
|
4043
|
-
constructor(options = {}) {
|
|
4044
|
-
options = options || {}
|
|
4045
|
-
super(options)
|
|
4046
|
-
const { _Invoice } = options._constructor || {}
|
|
4047
|
-
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4048
|
-
}
|
|
4049
|
-
static get _classname() {
|
|
4050
|
-
return 'InvoiceRepo'
|
|
4051
|
-
}
|
|
4052
|
-
init(options) {
|
|
4053
|
-
return this._Invoice.init(options)
|
|
4054
|
-
}
|
|
4055
|
-
}
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
;// ./lib/models/invoice/index.js
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
;// ./lib/models/keyValueObject/index.js
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
const paymentGateway_updateAllowedProps = [
|
|
4073
|
-
'active',
|
|
4074
|
-
'deleted',
|
|
4075
|
-
'label',
|
|
4076
|
-
'logoUrl',
|
|
4077
|
-
'name',
|
|
4078
|
-
'owner',
|
|
4079
|
-
'sandbox',
|
|
4080
|
-
'setting'
|
|
4081
|
-
]
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
class PaymentGateway {
|
|
4085
|
-
constructor(options = {}) {
|
|
4086
|
-
options = options || {}
|
|
4087
|
-
const id = options._id || options.id
|
|
4088
|
-
this.id = paymentGateway_setId(id)
|
|
4089
|
-
this._type = options._type || 'PaymentGateway'
|
|
4090
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4091
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4092
|
-
this.creator = options.creator
|
|
4093
|
-
this.deleted = options.deleted || false
|
|
4094
|
-
this.hasWebhook = options.hasWebhook || false
|
|
4095
|
-
this.label = options.label
|
|
4096
|
-
this.logoUrl = options.logoUrl
|
|
4097
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4098
|
-
this.name = options.name || ''
|
|
4099
|
-
this.owner = options.owner
|
|
4100
|
-
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4101
|
-
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4102
|
-
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4103
|
-
this.sandbox = options.sandbox || false
|
|
4104
|
-
this.setting = options.setting || null
|
|
4105
|
-
this.tenantCode = options.tenantCode
|
|
4106
|
-
}
|
|
4107
|
-
static dummyData() {
|
|
4108
|
-
return {
|
|
4109
|
-
name: 'name',
|
|
4110
|
-
tenantCode: 'tenantCode'
|
|
4111
|
-
}
|
|
4112
|
-
}
|
|
4113
|
-
static init(options = {}) {
|
|
4114
|
-
if (options instanceof this) {
|
|
4115
|
-
return options
|
|
4116
|
-
}
|
|
4117
|
-
const instance = new this(options)
|
|
4118
|
-
return instance.isValid ? instance : null
|
|
4119
|
-
}
|
|
4120
|
-
static initFromArray(arr = []) {
|
|
4121
|
-
if (Array.isArray(arr)) {
|
|
4122
|
-
return arr.map((a) => this.init(a))
|
|
4123
|
-
}
|
|
4124
|
-
return []
|
|
4125
|
-
}
|
|
4126
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4127
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4128
|
-
}
|
|
4129
|
-
static get _classname() {
|
|
4130
|
-
return 'PaymentGateway'
|
|
4131
|
-
}
|
|
4132
|
-
static get _superclass() {
|
|
4133
|
-
return 'PaymentGateway'
|
|
4134
|
-
}
|
|
4135
|
-
|
|
4136
|
-
// getters
|
|
4137
|
-
get isValid() {
|
|
4138
|
-
return !!this.name && !!this.tenantCode
|
|
4139
|
-
}
|
|
4140
|
-
|
|
4141
|
-
// instance methods
|
|
4142
|
-
async createPayment() {
|
|
4143
|
-
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4144
|
-
}
|
|
4145
|
-
async getAppPayParams() {
|
|
4146
|
-
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4147
|
-
}
|
|
4148
|
-
async updatePayment() {
|
|
4149
|
-
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4150
|
-
}
|
|
4151
|
-
async query() {
|
|
4152
|
-
throw new Error(`${this._classname} subclass should implement query`)
|
|
4153
|
-
}
|
|
4154
|
-
async submit() {
|
|
4155
|
-
throw new Error(`${this._classname} subclass should implement submit`)
|
|
4156
|
-
}
|
|
4157
|
-
|
|
4158
|
-
setCompletedRelatedStatus(status) {
|
|
4159
|
-
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4160
|
-
}
|
|
4161
|
-
|
|
4162
|
-
setModified() {
|
|
4163
|
-
this.modified = (new Date()).valueOf()
|
|
4164
|
-
return this
|
|
4165
|
-
}
|
|
4166
|
-
update(update) {
|
|
4167
|
-
Object.keys(update).forEach((key) => {
|
|
4168
|
-
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4169
|
-
this[key] = update[key]
|
|
4170
|
-
}
|
|
4171
|
-
})
|
|
4172
|
-
return this.setModified()
|
|
4173
|
-
}
|
|
4174
|
-
}
|
|
4175
|
-
|
|
4176
|
-
function paymentGateway_setCode(options, key) {
|
|
4075
|
+
function walletItem_setCode(options, key) {
|
|
4177
4076
|
const copyOptions = options || {}
|
|
4178
4077
|
if (copyOptions[key]) {
|
|
4179
4078
|
return copyOptions[key]
|
|
@@ -4181,38 +4080,30 @@ function paymentGateway_setCode(options, key) {
|
|
|
4181
4080
|
return stringHelper.setCode()
|
|
4182
4081
|
}
|
|
4183
4082
|
|
|
4184
|
-
function paymentGateway_setId(id) {
|
|
4185
|
-
if (id && typeof id.toString === 'function') {
|
|
4186
|
-
return id.toString()
|
|
4187
|
-
}
|
|
4188
|
-
return id
|
|
4189
|
-
}
|
|
4190
|
-
|
|
4191
4083
|
|
|
4192
4084
|
|
|
4193
|
-
;// ./lib/models/
|
|
4085
|
+
;// ./lib/models/walletItem/walletItemRepo.js
|
|
4194
4086
|
|
|
4195
4087
|
|
|
4196
4088
|
|
|
4197
|
-
class
|
|
4089
|
+
class WalletItemRepo extends q_utilities_namespaceObject.Repo {
|
|
4198
4090
|
constructor(options = {}) {
|
|
4199
4091
|
options = options || {}
|
|
4200
4092
|
super(options)
|
|
4201
|
-
const {
|
|
4202
|
-
this.
|
|
4093
|
+
const { _WalletItem } = options._constructor || {}
|
|
4094
|
+
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4203
4095
|
}
|
|
4204
4096
|
static get _classname() {
|
|
4205
|
-
return '
|
|
4097
|
+
return 'WalletItemRepo'
|
|
4206
4098
|
}
|
|
4207
4099
|
init(options) {
|
|
4208
|
-
return this.
|
|
4100
|
+
return this._WalletItem.init(options)
|
|
4209
4101
|
}
|
|
4210
4102
|
}
|
|
4211
4103
|
|
|
4212
4104
|
|
|
4213
4105
|
|
|
4214
|
-
;// ./lib/models/
|
|
4215
|
-
|
|
4106
|
+
;// ./lib/models/walletItem/index.js
|
|
4216
4107
|
|
|
4217
4108
|
|
|
4218
4109
|
|
|
@@ -4225,7 +4116,6 @@ class PaymentGatewayRepo extends q_utilities_namespaceObject.Repo {
|
|
|
4225
4116
|
|
|
4226
4117
|
|
|
4227
4118
|
|
|
4228
|
-
|
|
4229
4119
|
const transaction_updateAllowedProps = [
|
|
4230
4120
|
'active',
|
|
4231
4121
|
'amount',
|
|
@@ -4239,16 +4129,17 @@ const transaction_updateAllowedProps = [
|
|
|
4239
4129
|
class Transaction {
|
|
4240
4130
|
constructor(options = {}) {
|
|
4241
4131
|
options = options || {}
|
|
4242
|
-
const { _Amount,
|
|
4132
|
+
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
4243
4133
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4244
|
-
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4245
|
-
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4246
4134
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4135
|
+
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4247
4136
|
|
|
4248
4137
|
this._coupons = options._coupons
|
|
4249
4138
|
this._creditNotes = options._creditNotes
|
|
4250
4139
|
this._invoice = options._invoice
|
|
4251
4140
|
this._paymentGateway = options._paymentGateway
|
|
4141
|
+
this._paymentResults = options._paymentResults
|
|
4142
|
+
this._walletItems = options._walletItems
|
|
4252
4143
|
|
|
4253
4144
|
const id = options._id || options.id
|
|
4254
4145
|
this.id = transaction_setId(id)
|
|
@@ -4306,9 +4197,6 @@ class Transaction {
|
|
|
4306
4197
|
get isValid() {
|
|
4307
4198
|
return !!this.tenantCode
|
|
4308
4199
|
}
|
|
4309
|
-
get invoice() {
|
|
4310
|
-
return this._Invoice.init(this._invoice)
|
|
4311
|
-
}
|
|
4312
4200
|
get isActive() {
|
|
4313
4201
|
return this.active === true
|
|
4314
4202
|
}
|
|
@@ -4362,10 +4250,9 @@ class Transaction {
|
|
|
4362
4250
|
get isWaived() {
|
|
4363
4251
|
return this.status.isWaived
|
|
4364
4252
|
}
|
|
4365
|
-
get
|
|
4366
|
-
return this.
|
|
4253
|
+
get walletItems() {
|
|
4254
|
+
return this._WalletItem.initOnlyValidFromArray(this._walletItems)
|
|
4367
4255
|
}
|
|
4368
|
-
|
|
4369
4256
|
// get totalAmount() {
|
|
4370
4257
|
// return this.total.getAmount()
|
|
4371
4258
|
// }
|
|
@@ -4503,17 +4390,303 @@ class Transaction {
|
|
|
4503
4390
|
}
|
|
4504
4391
|
update(update) {
|
|
4505
4392
|
Object.keys(update).forEach((key) => {
|
|
4506
|
-
if (transaction_updateAllowedProps.includes(key)) {
|
|
4507
|
-
if (key === 'amount') {
|
|
4393
|
+
if (transaction_updateAllowedProps.includes(key)) {
|
|
4394
|
+
if (key === 'amount') {
|
|
4395
|
+
this[key] = this._Amount.init(update[key])
|
|
4396
|
+
} else if (key === 'metadata') {
|
|
4397
|
+
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4398
|
+
} else if (key === 'remarks') {
|
|
4399
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4400
|
+
} else if (key === 'status') {
|
|
4401
|
+
this[key] = this._Status.init(update[key])
|
|
4402
|
+
// } else if (key === 'refundedAmount') {
|
|
4403
|
+
// this[key] = this.updateTotal(key, update[key])
|
|
4404
|
+
} else {
|
|
4405
|
+
this[key] = update[key]
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
})
|
|
4409
|
+
return this.setModified()
|
|
4410
|
+
}
|
|
4411
|
+
// updatePayment(payment = {}) {
|
|
4412
|
+
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
4413
|
+
// return this
|
|
4414
|
+
// }
|
|
4415
|
+
// updateTotal(key, obj) {
|
|
4416
|
+
// if (obj instanceof Total) {
|
|
4417
|
+
// return this[key].updateTotal(obj)
|
|
4418
|
+
// }
|
|
4419
|
+
// return setTotal(obj, key)
|
|
4420
|
+
// }
|
|
4421
|
+
}
|
|
4422
|
+
|
|
4423
|
+
function transaction_setCode(options, key) {
|
|
4424
|
+
const copyOptions = options || {}
|
|
4425
|
+
if (copyOptions[key]) {
|
|
4426
|
+
return copyOptions[key]
|
|
4427
|
+
}
|
|
4428
|
+
return stringHelper.setCode()
|
|
4429
|
+
}
|
|
4430
|
+
|
|
4431
|
+
function transaction_setId(id) {
|
|
4432
|
+
if (id && typeof id.toString === 'function') {
|
|
4433
|
+
return id.toString()
|
|
4434
|
+
}
|
|
4435
|
+
return id
|
|
4436
|
+
}
|
|
4437
|
+
|
|
4438
|
+
// function setTotal(obj, label) {
|
|
4439
|
+
// obj = obj || {}
|
|
4440
|
+
// return Total.init({ ...obj, label: obj.label || label })
|
|
4441
|
+
// }
|
|
4442
|
+
|
|
4443
|
+
|
|
4444
|
+
|
|
4445
|
+
;// ./lib/models/transaction/transactionRepo.js
|
|
4446
|
+
|
|
4447
|
+
|
|
4448
|
+
|
|
4449
|
+
class TransactionRepo extends q_utilities_namespaceObject.Repo {
|
|
4450
|
+
constructor(options = {}) {
|
|
4451
|
+
options = options || {}
|
|
4452
|
+
super(options)
|
|
4453
|
+
const { _Transaction } = options._constructor || {}
|
|
4454
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4455
|
+
}
|
|
4456
|
+
static get _classname() {
|
|
4457
|
+
return 'TransactionRepo'
|
|
4458
|
+
}
|
|
4459
|
+
init(options) {
|
|
4460
|
+
return this._Transaction.init(options)
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4464
|
+
|
|
4465
|
+
|
|
4466
|
+
;// ./lib/models/transaction/index.js
|
|
4467
|
+
|
|
4468
|
+
|
|
4469
|
+
|
|
4470
|
+
|
|
4471
|
+
|
|
4472
|
+
|
|
4473
|
+
;// ./lib/models/invoice/invoice.js
|
|
4474
|
+
|
|
4475
|
+
|
|
4476
|
+
|
|
4477
|
+
|
|
4478
|
+
|
|
4479
|
+
|
|
4480
|
+
|
|
4481
|
+
|
|
4482
|
+
|
|
4483
|
+
const invoice_updateAllowedProps = [
|
|
4484
|
+
'active',
|
|
4485
|
+
'checkoutDateTime',
|
|
4486
|
+
'deleted',
|
|
4487
|
+
'description',
|
|
4488
|
+
'invoiceDate',
|
|
4489
|
+
'issuer',
|
|
4490
|
+
'metadata',
|
|
4491
|
+
'remarks',
|
|
4492
|
+
'revisionNumber',
|
|
4493
|
+
'status'
|
|
4494
|
+
]
|
|
4495
|
+
|
|
4496
|
+
class Invoice {
|
|
4497
|
+
constructor(options) {
|
|
4498
|
+
options = options || {}
|
|
4499
|
+
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
4500
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4501
|
+
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
4502
|
+
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
4503
|
+
this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
|
|
4504
|
+
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4505
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4506
|
+
|
|
4507
|
+
this._cart = options._cart
|
|
4508
|
+
this._invoiceLines = options._invoiceLines
|
|
4509
|
+
this._transactions = options._transactions
|
|
4510
|
+
|
|
4511
|
+
const id = options._id || options.id
|
|
4512
|
+
this.id = invoice_setId(id)
|
|
4513
|
+
this._type = options._type || 'Invoice'
|
|
4514
|
+
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4515
|
+
this.amount = this._Amount.init(options.amount)
|
|
4516
|
+
this.cartCode = options.cartCode
|
|
4517
|
+
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4518
|
+
this.created = options.created || (new Date()).valueOf()
|
|
4519
|
+
this.creator = options.creator
|
|
4520
|
+
this.deleted = options.deleted || false
|
|
4521
|
+
this.description = options.description
|
|
4522
|
+
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4523
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4524
|
+
this.invoiceNumber = options.invoiceNumber
|
|
4525
|
+
this.issuer = this._Issuer.init(options.issuer)
|
|
4526
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4527
|
+
this.modified = options.modified || (new Date()).valueOf()
|
|
4528
|
+
this.owner = options.owner
|
|
4529
|
+
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4530
|
+
this.revisionNumber = options.revisionNumber || 1
|
|
4531
|
+
this.status = this._Status.init(options.status)
|
|
4532
|
+
this.tenantCode = options.tenantCode
|
|
4533
|
+
}
|
|
4534
|
+
|
|
4535
|
+
static dummyData() {
|
|
4536
|
+
return {
|
|
4537
|
+
tenantCode: 'tenantCode'
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
static init(options = {}) {
|
|
4541
|
+
if (options instanceof this) {
|
|
4542
|
+
return options
|
|
4543
|
+
}
|
|
4544
|
+
const instance = new this(options)
|
|
4545
|
+
return instance.isValid ? instance : null
|
|
4546
|
+
}
|
|
4547
|
+
static initFromArray(arr = []) {
|
|
4548
|
+
if (Array.isArray(arr)) {
|
|
4549
|
+
return arr.map((a) => this.init(a))
|
|
4550
|
+
}
|
|
4551
|
+
return []
|
|
4552
|
+
}
|
|
4553
|
+
static initOnlyValidFromArray(arr = []) {
|
|
4554
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
4555
|
+
}
|
|
4556
|
+
static get _classname() {
|
|
4557
|
+
return 'Invoice'
|
|
4558
|
+
}
|
|
4559
|
+
static get _superclass() {
|
|
4560
|
+
return 'Invoice'
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4563
|
+
get isValid() {
|
|
4564
|
+
return !!this.tenantCode
|
|
4565
|
+
}
|
|
4566
|
+
get cart() {
|
|
4567
|
+
return this._Cart.init(this._cart)
|
|
4568
|
+
}
|
|
4569
|
+
get invoiceLines() {
|
|
4570
|
+
return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
|
|
4571
|
+
}
|
|
4572
|
+
get merchandises() {
|
|
4573
|
+
return (this.invoiceLines || []).map((i) => {
|
|
4574
|
+
return i.merchandise
|
|
4575
|
+
}).filter((i) => i)
|
|
4576
|
+
}
|
|
4577
|
+
get merchandisesSummary() {
|
|
4578
|
+
return this.merchandises.reduce((acc, m) => {
|
|
4579
|
+
const found = acc.find((a) => {
|
|
4580
|
+
return a.merchandiseCode === m.merchandiseCode
|
|
4581
|
+
})
|
|
4582
|
+
if (found) {
|
|
4583
|
+
found.qty += 1
|
|
4584
|
+
} else {
|
|
4585
|
+
acc.push({
|
|
4586
|
+
...m.summary,
|
|
4587
|
+
qty: 1
|
|
4588
|
+
})
|
|
4589
|
+
}
|
|
4590
|
+
return acc
|
|
4591
|
+
}, [])
|
|
4592
|
+
}
|
|
4593
|
+
get products() {
|
|
4594
|
+
return (this.merchandises || []).reduce((acc, m) => {
|
|
4595
|
+
if (m.products) {
|
|
4596
|
+
acc = acc.concat(m.products)
|
|
4597
|
+
}
|
|
4598
|
+
return acc
|
|
4599
|
+
}, [])
|
|
4600
|
+
}
|
|
4601
|
+
get productsSummary() {
|
|
4602
|
+
return this.products.reduce((acc, p) => {
|
|
4603
|
+
const found = acc.find((a) => {
|
|
4604
|
+
return a.productCode === p.productCode
|
|
4605
|
+
})
|
|
4606
|
+
if (found) {
|
|
4607
|
+
found.qty += 1
|
|
4608
|
+
} else {
|
|
4609
|
+
acc.push({
|
|
4610
|
+
...p.summary,
|
|
4611
|
+
qty: 1
|
|
4612
|
+
})
|
|
4613
|
+
}
|
|
4614
|
+
return acc
|
|
4615
|
+
}, [])
|
|
4616
|
+
}
|
|
4617
|
+
get transactions() {
|
|
4618
|
+
return this._Transaction.initOnlyValidFromArray(this._transactions)
|
|
4619
|
+
}
|
|
4620
|
+
get walletItems() {
|
|
4621
|
+
return (this.transactions || []).reduce((acc, t) => {
|
|
4622
|
+
if (t.walletItems) {
|
|
4623
|
+
acc = acc.concat(t.walletItems)
|
|
4624
|
+
}
|
|
4625
|
+
return acc
|
|
4626
|
+
}, [])
|
|
4627
|
+
}
|
|
4628
|
+
|
|
4629
|
+
allowCancel() {
|
|
4630
|
+
return this.status.allowCancel()
|
|
4631
|
+
}
|
|
4632
|
+
|
|
4633
|
+
// instance methods
|
|
4634
|
+
getAmount() {
|
|
4635
|
+
return this.amount
|
|
4636
|
+
}
|
|
4637
|
+
|
|
4638
|
+
getCurrencyCode() {
|
|
4639
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
4640
|
+
}
|
|
4641
|
+
|
|
4642
|
+
getFullInvoiceNumber(delimiter = '.') {
|
|
4643
|
+
return `${this.invoiceNumber}${delimiter}${this.revisionNumber}`
|
|
4644
|
+
}
|
|
4645
|
+
|
|
4646
|
+
increaseRevisionNumber() {
|
|
4647
|
+
this.revisionNumber += 1
|
|
4648
|
+
return this
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
setCancelled() {
|
|
4652
|
+
return this.status.setCancelled()
|
|
4653
|
+
}
|
|
4654
|
+
|
|
4655
|
+
setCheckoutDateTime(timestamp) {
|
|
4656
|
+
if (typeof timestamp === 'number') {
|
|
4657
|
+
this.checkoutDateTime = timestamp
|
|
4658
|
+
}
|
|
4659
|
+
return this
|
|
4660
|
+
}
|
|
4661
|
+
|
|
4662
|
+
setModified() {
|
|
4663
|
+
this.modified = (new Date()).valueOf()
|
|
4664
|
+
return this
|
|
4665
|
+
}
|
|
4666
|
+
|
|
4667
|
+
setCompleted() {
|
|
4668
|
+
this.status.setCompleted()
|
|
4669
|
+
return this.setModified()
|
|
4670
|
+
}
|
|
4671
|
+
|
|
4672
|
+
setWaived() {
|
|
4673
|
+
this.status.setWaived()
|
|
4674
|
+
return this.setModified()
|
|
4675
|
+
}
|
|
4676
|
+
|
|
4677
|
+
update(update) {
|
|
4678
|
+
Object.keys(update).forEach((key) => {
|
|
4679
|
+
if (invoice_updateAllowedProps.includes(key)) {
|
|
4680
|
+
if (key === 'remarks') {
|
|
4681
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4682
|
+
} else if (key === 'amount') {
|
|
4508
4683
|
this[key] = this._Amount.init(update[key])
|
|
4509
4684
|
} else if (key === 'metadata') {
|
|
4510
4685
|
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4511
|
-
} else if (key === '
|
|
4512
|
-
this[key] =
|
|
4686
|
+
} else if (key === 'issuer') {
|
|
4687
|
+
this[key] = this._Issuer.init(update[key])
|
|
4513
4688
|
} else if (key === 'status') {
|
|
4514
4689
|
this[key] = this._Status.init(update[key])
|
|
4515
|
-
// } else if (key === 'refundedAmount') {
|
|
4516
|
-
// this[key] = this.updateTotal(key, update[key])
|
|
4517
4690
|
} else {
|
|
4518
4691
|
this[key] = update[key]
|
|
4519
4692
|
}
|
|
@@ -4521,19 +4694,9 @@ class Transaction {
|
|
|
4521
4694
|
})
|
|
4522
4695
|
return this.setModified()
|
|
4523
4696
|
}
|
|
4524
|
-
// updatePayment(payment = {}) {
|
|
4525
|
-
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
4526
|
-
// return this
|
|
4527
|
-
// }
|
|
4528
|
-
// updateTotal(key, obj) {
|
|
4529
|
-
// if (obj instanceof Total) {
|
|
4530
|
-
// return this[key].updateTotal(obj)
|
|
4531
|
-
// }
|
|
4532
|
-
// return setTotal(obj, key)
|
|
4533
|
-
// }
|
|
4534
4697
|
}
|
|
4535
4698
|
|
|
4536
|
-
function
|
|
4699
|
+
function invoice_setCode(options, key) {
|
|
4537
4700
|
const copyOptions = options || {}
|
|
4538
4701
|
if (copyOptions[key]) {
|
|
4539
4702
|
return copyOptions[key]
|
|
@@ -4541,97 +4704,88 @@ function transaction_setCode(options, key) {
|
|
|
4541
4704
|
return stringHelper.setCode()
|
|
4542
4705
|
}
|
|
4543
4706
|
|
|
4544
|
-
function
|
|
4707
|
+
function invoice_setId(id) {
|
|
4545
4708
|
if (id && typeof id.toString === 'function') {
|
|
4546
4709
|
return id.toString()
|
|
4547
4710
|
}
|
|
4548
4711
|
return id
|
|
4549
4712
|
}
|
|
4550
4713
|
|
|
4551
|
-
// function setTotal(obj, label) {
|
|
4552
|
-
// obj = obj || {}
|
|
4553
|
-
// return Total.init({ ...obj, label: obj.label || label })
|
|
4554
|
-
// }
|
|
4555
|
-
|
|
4556
4714
|
|
|
4557
4715
|
|
|
4558
|
-
;// ./lib/models/
|
|
4716
|
+
;// ./lib/models/invoice/invoiceRepo.js
|
|
4559
4717
|
|
|
4560
4718
|
|
|
4561
4719
|
|
|
4562
|
-
class
|
|
4720
|
+
class InvoiceRepo extends q_utilities_namespaceObject.Repo {
|
|
4563
4721
|
constructor(options = {}) {
|
|
4564
4722
|
options = options || {}
|
|
4565
4723
|
super(options)
|
|
4566
|
-
const {
|
|
4567
|
-
this.
|
|
4724
|
+
const { _Invoice } = options._constructor || {}
|
|
4725
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4568
4726
|
}
|
|
4569
4727
|
static get _classname() {
|
|
4570
|
-
return '
|
|
4728
|
+
return 'InvoiceRepo'
|
|
4571
4729
|
}
|
|
4572
4730
|
init(options) {
|
|
4573
|
-
return this.
|
|
4731
|
+
return this._Invoice.init(options)
|
|
4574
4732
|
}
|
|
4575
4733
|
}
|
|
4576
4734
|
|
|
4577
4735
|
|
|
4578
4736
|
|
|
4579
|
-
;// ./lib/models/
|
|
4737
|
+
;// ./lib/models/invoice/index.js
|
|
4580
4738
|
|
|
4581
4739
|
|
|
4582
4740
|
|
|
4583
4741
|
|
|
4584
4742
|
|
|
4585
4743
|
|
|
4586
|
-
;// ./lib/models/
|
|
4744
|
+
;// ./lib/models/keyValueObject/index.js
|
|
4587
4745
|
|
|
4588
4746
|
|
|
4747
|
+
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4589
4748
|
|
|
4590
4749
|
|
|
4591
|
-
const
|
|
4750
|
+
const paymentGateway_updateAllowedProps = [
|
|
4592
4751
|
'active',
|
|
4593
4752
|
'deleted',
|
|
4594
|
-
'
|
|
4595
|
-
'
|
|
4753
|
+
'label',
|
|
4754
|
+
'logoUrl',
|
|
4755
|
+
'name',
|
|
4756
|
+
'owner',
|
|
4757
|
+
'sandbox',
|
|
4758
|
+
'setting'
|
|
4596
4759
|
]
|
|
4597
4760
|
|
|
4598
|
-
|
|
4761
|
+
|
|
4762
|
+
class PaymentGateway {
|
|
4599
4763
|
constructor(options = {}) {
|
|
4600
4764
|
options = options || {}
|
|
4601
|
-
const { _Transaction } = options._constructor || {}
|
|
4602
|
-
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4603
|
-
|
|
4604
|
-
this._transaction = options._transaction
|
|
4605
|
-
this._type = options._type || 'PaymentResult'
|
|
4606
|
-
|
|
4607
4765
|
const id = options._id || options.id
|
|
4608
|
-
this.id =
|
|
4609
|
-
this.
|
|
4766
|
+
this.id = paymentGateway_setId(id)
|
|
4767
|
+
this._type = options._type || 'PaymentGateway'
|
|
4768
|
+
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4610
4769
|
this.created = options.created || (new Date()).valueOf()
|
|
4611
4770
|
this.creator = options.creator
|
|
4612
4771
|
this.deleted = options.deleted || false
|
|
4613
|
-
this.
|
|
4772
|
+
this.hasWebhook = options.hasWebhook || false
|
|
4773
|
+
this.label = options.label
|
|
4774
|
+
this.logoUrl = options.logoUrl
|
|
4614
4775
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4776
|
+
this.name = options.name || ''
|
|
4615
4777
|
this.owner = options.owner
|
|
4616
|
-
this.
|
|
4778
|
+
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4779
|
+
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4617
4780
|
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4618
|
-
this.
|
|
4619
|
-
this.
|
|
4620
|
-
this.resultRef = options.resultRef
|
|
4621
|
-
this.resultType = options.resultType
|
|
4781
|
+
this.sandbox = options.sandbox || false
|
|
4782
|
+
this.setting = options.setting || null
|
|
4622
4783
|
this.tenantCode = options.tenantCode
|
|
4623
|
-
// this.transaction = this._Transaction.init(options.transaction)
|
|
4624
|
-
this.transactionCode = options.transactionCode
|
|
4625
4784
|
}
|
|
4626
|
-
|
|
4627
|
-
// class method
|
|
4628
4785
|
static dummyData() {
|
|
4629
4786
|
return {
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
resultType: 'resultType',
|
|
4633
|
-
tenantCode: 'tenantCode',
|
|
4634
|
-
transactionCode: 'transactionCode'
|
|
4787
|
+
name: 'name',
|
|
4788
|
+
tenantCode: 'tenantCode'
|
|
4635
4789
|
}
|
|
4636
4790
|
}
|
|
4637
4791
|
static init(options = {}) {
|
|
@@ -4651,117 +4805,53 @@ class PaymentResult {
|
|
|
4651
4805
|
return this.initFromArray(arr).filter((i) => i)
|
|
4652
4806
|
}
|
|
4653
4807
|
static get _classname() {
|
|
4654
|
-
return '
|
|
4808
|
+
return 'PaymentGateway'
|
|
4655
4809
|
}
|
|
4656
4810
|
static get _superclass() {
|
|
4657
|
-
return '
|
|
4811
|
+
return 'PaymentGateway'
|
|
4658
4812
|
}
|
|
4659
4813
|
|
|
4660
4814
|
// getters
|
|
4661
4815
|
get isValid() {
|
|
4662
|
-
return !!this.
|
|
4663
|
-
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
4664
|
-
}
|
|
4665
|
-
get amount() {
|
|
4666
|
-
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4667
|
-
}
|
|
4668
|
-
get paymentMethod() {
|
|
4669
|
-
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4670
|
-
}
|
|
4671
|
-
get transaction() {
|
|
4672
|
-
return this._transaction.init(this._transaction)
|
|
4816
|
+
return !!this.name && !!this.tenantCode
|
|
4673
4817
|
}
|
|
4674
4818
|
|
|
4675
4819
|
// instance methods
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
// }
|
|
4679
|
-
addMetadata(key, value) {
|
|
4680
|
-
q_utilities_namespaceObject.Metadata.addItem(this.metadata, key, value)
|
|
4681
|
-
return this
|
|
4682
|
-
}
|
|
4683
|
-
addRemark(key, value) {
|
|
4684
|
-
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, key, value)
|
|
4685
|
-
return this
|
|
4686
|
-
}
|
|
4687
|
-
|
|
4688
|
-
compareStatus(paymentResult) {
|
|
4689
|
-
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4690
|
-
}
|
|
4691
|
-
getPaidAmount() {
|
|
4692
|
-
throw new Error(`${this.paymentResultType} subclass should implement getPaidAmount`)
|
|
4693
|
-
}
|
|
4694
|
-
getPaidTimestamp() {
|
|
4695
|
-
throw new Error(
|
|
4696
|
-
`${this.paymentResultType} subclass should implement getPaidTimestamp in milliseconds`
|
|
4697
|
-
)
|
|
4698
|
-
}
|
|
4699
|
-
getPaymentCode() {
|
|
4700
|
-
throw new Error(`${this.paymentResultType} subclass should implement getPaymentCode`)
|
|
4820
|
+
async createPayment() {
|
|
4821
|
+
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4701
4822
|
}
|
|
4702
|
-
|
|
4703
|
-
throw new Error(`${this.
|
|
4823
|
+
async getAppPayParams() {
|
|
4824
|
+
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4704
4825
|
}
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
return { payment, err: new Error('the payment result is not for this payment') }
|
|
4708
|
-
}
|
|
4709
|
-
if (!this.isSameAmount(payment)) {
|
|
4710
|
-
return { payment, err: new Error('the amount was not matched') }
|
|
4711
|
-
}
|
|
4712
|
-
try {
|
|
4713
|
-
payment.settled()
|
|
4714
|
-
payment
|
|
4715
|
-
.setPaidAmount(this.getPaidAmount())
|
|
4716
|
-
.setPaidTimestamp(this.getPaidTimestamp())
|
|
4717
|
-
.setPaymentResultCode(this.paymentResultCode)
|
|
4718
|
-
return { payment, err: null }
|
|
4719
|
-
} catch (err) {
|
|
4720
|
-
return { payment, err }
|
|
4721
|
-
}
|
|
4826
|
+
async updatePayment() {
|
|
4827
|
+
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4722
4828
|
}
|
|
4723
|
-
|
|
4724
|
-
|
|
4829
|
+
async query() {
|
|
4830
|
+
throw new Error(`${this._classname} subclass should implement query`)
|
|
4725
4831
|
}
|
|
4726
|
-
|
|
4727
|
-
|
|
4832
|
+
async submit() {
|
|
4833
|
+
throw new Error(`${this._classname} subclass should implement submit`)
|
|
4728
4834
|
}
|
|
4729
|
-
|
|
4730
|
-
|
|
4835
|
+
|
|
4836
|
+
setCompletedRelatedStatus(status) {
|
|
4837
|
+
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4731
4838
|
}
|
|
4839
|
+
|
|
4732
4840
|
setModified() {
|
|
4733
4841
|
this.modified = (new Date()).valueOf()
|
|
4734
4842
|
return this
|
|
4735
4843
|
}
|
|
4736
|
-
setupMetadata() {
|
|
4737
|
-
const amount = this.amount
|
|
4738
|
-
const paymentMethod = this.paymentMethod
|
|
4739
|
-
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
4740
|
-
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
4741
|
-
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
4742
|
-
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
4743
|
-
return this
|
|
4744
|
-
}
|
|
4745
|
-
setupRemarks() {
|
|
4746
|
-
return this.setupMetadata()
|
|
4747
|
-
}
|
|
4748
4844
|
update(update) {
|
|
4749
4845
|
Object.keys(update).forEach((key) => {
|
|
4750
|
-
if (
|
|
4751
|
-
|
|
4752
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4753
|
-
} else if (key === 'remarks') {
|
|
4754
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4755
|
-
} else {
|
|
4756
|
-
this[key] = update[key]
|
|
4757
|
-
}
|
|
4846
|
+
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4847
|
+
this[key] = update[key]
|
|
4758
4848
|
}
|
|
4759
4849
|
})
|
|
4760
4850
|
return this.setModified()
|
|
4761
4851
|
}
|
|
4762
4852
|
}
|
|
4763
4853
|
|
|
4764
|
-
function
|
|
4854
|
+
function paymentGateway_setCode(options, key) {
|
|
4765
4855
|
const copyOptions = options || {}
|
|
4766
4856
|
if (copyOptions[key]) {
|
|
4767
4857
|
return copyOptions[key]
|
|
@@ -4769,7 +4859,7 @@ function paymentResult_setCode(options, key) {
|
|
|
4769
4859
|
return stringHelper.setCode()
|
|
4770
4860
|
}
|
|
4771
4861
|
|
|
4772
|
-
function
|
|
4862
|
+
function paymentGateway_setId(id) {
|
|
4773
4863
|
if (id && typeof id.toString === 'function') {
|
|
4774
4864
|
return id.toString()
|
|
4775
4865
|
}
|
|
@@ -4778,95 +4868,81 @@ function paymentResult_setId(id) {
|
|
|
4778
4868
|
|
|
4779
4869
|
|
|
4780
4870
|
|
|
4781
|
-
;// ./lib/models/
|
|
4871
|
+
;// ./lib/models/paymentGateway/paymentGatewayRepo.js
|
|
4782
4872
|
|
|
4783
4873
|
|
|
4784
4874
|
|
|
4785
|
-
class
|
|
4875
|
+
class PaymentGatewayRepo extends q_utilities_namespaceObject.Repo {
|
|
4786
4876
|
constructor(options = {}) {
|
|
4787
4877
|
options = options || {}
|
|
4788
4878
|
super(options)
|
|
4789
|
-
const {
|
|
4790
|
-
this.
|
|
4879
|
+
const { _PaymentGateway } = options._constructor || {}
|
|
4880
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4791
4881
|
}
|
|
4792
4882
|
static get _classname() {
|
|
4793
|
-
return '
|
|
4883
|
+
return 'PaymentGatewayRepo'
|
|
4794
4884
|
}
|
|
4795
4885
|
init(options) {
|
|
4796
|
-
return this.
|
|
4886
|
+
return this._PaymentGateway.init(options)
|
|
4797
4887
|
}
|
|
4798
4888
|
}
|
|
4799
4889
|
|
|
4800
4890
|
|
|
4801
4891
|
|
|
4802
|
-
;// ./lib/models/
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
;// ./lib/models/status/index.js
|
|
4810
|
-
|
|
4892
|
+
;// ./lib/models/paymentGateway/index.js
|
|
4811
4893
|
|
|
4812
4894
|
|
|
4813
4895
|
|
|
4814
4896
|
|
|
4815
|
-
;// ./lib/models/walletItem/walletItem.js
|
|
4816
4897
|
|
|
4817
4898
|
|
|
4899
|
+
;// ./lib/models/paymentResult/paymentResult.js
|
|
4818
4900
|
|
|
4819
4901
|
|
|
4820
4902
|
|
|
4821
4903
|
|
|
4822
|
-
const
|
|
4904
|
+
const paymentResult_updateAllowedProps = [
|
|
4823
4905
|
'active',
|
|
4824
4906
|
'deleted',
|
|
4825
|
-
'owner',
|
|
4826
|
-
'purchaseOptions',
|
|
4827
|
-
'qty',
|
|
4828
4907
|
'remarks',
|
|
4829
|
-
'
|
|
4908
|
+
'result'
|
|
4830
4909
|
]
|
|
4831
4910
|
|
|
4832
|
-
class
|
|
4911
|
+
class PaymentResult {
|
|
4833
4912
|
constructor(options = {}) {
|
|
4834
4913
|
options = options || {}
|
|
4835
|
-
const {
|
|
4836
|
-
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
4837
|
-
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4914
|
+
const { _Transaction } = options._constructor || {}
|
|
4838
4915
|
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4839
4916
|
|
|
4840
|
-
this._product = options._product
|
|
4841
|
-
this._tenant = options._tenant
|
|
4842
4917
|
this._transaction = options._transaction
|
|
4918
|
+
this._type = options._type || 'PaymentResult'
|
|
4843
4919
|
|
|
4844
4920
|
const id = options._id || options.id
|
|
4845
|
-
this.id =
|
|
4846
|
-
this.active =
|
|
4921
|
+
this.id = paymentResult_setId(id)
|
|
4922
|
+
this.active = typeof options.active !== 'undefined' ? !!options.active : true
|
|
4847
4923
|
this.created = options.created || (new Date()).valueOf()
|
|
4848
4924
|
this.creator = options.creator
|
|
4849
4925
|
this.deleted = options.deleted || false
|
|
4850
4926
|
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4851
4927
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4852
4928
|
this.owner = options.owner
|
|
4853
|
-
this.
|
|
4854
|
-
this.
|
|
4855
|
-
this.qty = options.qty || 1
|
|
4929
|
+
this.paymentResultCode = paymentResult_setCode(options, 'paymentResultCode')
|
|
4930
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4856
4931
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4857
|
-
this.
|
|
4932
|
+
this.result = options.result
|
|
4933
|
+
this.resultRef = options.resultRef
|
|
4934
|
+
this.resultType = options.resultType
|
|
4858
4935
|
this.tenantCode = options.tenantCode
|
|
4936
|
+
// this.transaction = this._Transaction.init(options.transaction)
|
|
4859
4937
|
this.transactionCode = options.transactionCode
|
|
4860
|
-
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
4861
4938
|
}
|
|
4862
4939
|
|
|
4863
|
-
//
|
|
4940
|
+
// class method
|
|
4864
4941
|
static dummyData() {
|
|
4865
4942
|
return {
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
status: Status.dummyData(),
|
|
4943
|
+
paymentResultType: 'PaymentResult',
|
|
4944
|
+
result: { id: 'resultId' },
|
|
4945
|
+
resultType: 'resultType',
|
|
4870
4946
|
tenantCode: 'tenantCode',
|
|
4871
4947
|
transactionCode: 'transactionCode'
|
|
4872
4948
|
}
|
|
@@ -4888,180 +4964,107 @@ class WalletItem {
|
|
|
4888
4964
|
return this.initFromArray(arr).filter((i) => i)
|
|
4889
4965
|
}
|
|
4890
4966
|
static get _classname() {
|
|
4891
|
-
return '
|
|
4967
|
+
return 'PaymentResult'
|
|
4892
4968
|
}
|
|
4893
4969
|
static get _superclass() {
|
|
4894
|
-
return '
|
|
4970
|
+
return 'PaymentResult'
|
|
4895
4971
|
}
|
|
4896
4972
|
|
|
4897
4973
|
// getters
|
|
4898
4974
|
get isValid() {
|
|
4899
|
-
return !!this.tenantCode && !!this.
|
|
4900
|
-
|
|
4901
|
-
get isAssigned() {
|
|
4902
|
-
return this.status.isAssigned
|
|
4903
|
-
}
|
|
4904
|
-
get isCancelled() {
|
|
4905
|
-
return this.status.isCancelled
|
|
4906
|
-
}
|
|
4907
|
-
get isCompleted() {
|
|
4908
|
-
return this.status.isCompleted
|
|
4909
|
-
}
|
|
4910
|
-
get isConfirmed() {
|
|
4911
|
-
return this.status.isConfirmed
|
|
4912
|
-
}
|
|
4913
|
-
get isDelivered() {
|
|
4914
|
-
return this.status.isDelivered
|
|
4915
|
-
}
|
|
4916
|
-
get isOwned() {
|
|
4917
|
-
return (
|
|
4918
|
-
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
4919
|
-
&& (
|
|
4920
|
-
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
4921
|
-
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
4922
|
-
|| (this.isRedeemed && !this.isAssigned && !this.isConfirmed)
|
|
4923
|
-
|| (this.isAssigned && this.isConfirmed)
|
|
4924
|
-
)
|
|
4925
|
-
)
|
|
4926
|
-
}
|
|
4927
|
-
get isPaid() {
|
|
4928
|
-
return this.status.isPaid
|
|
4929
|
-
}
|
|
4930
|
-
get isPending() {
|
|
4931
|
-
return this.status.isPending
|
|
4932
|
-
}
|
|
4933
|
-
get isRedeemed() {
|
|
4934
|
-
return this.status.redeemed
|
|
4975
|
+
return !!this.resultType && !!this.tenantCode && !!this.transactionCode
|
|
4976
|
+
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
4935
4977
|
}
|
|
4936
|
-
get
|
|
4937
|
-
|
|
4978
|
+
get amount() {
|
|
4979
|
+
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4938
4980
|
}
|
|
4939
|
-
get
|
|
4940
|
-
|
|
4981
|
+
get paymentMethod() {
|
|
4982
|
+
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4941
4983
|
}
|
|
4942
|
-
get
|
|
4943
|
-
return this.
|
|
4984
|
+
get transaction() {
|
|
4985
|
+
return this._transaction.init(this._transaction)
|
|
4944
4986
|
}
|
|
4945
|
-
|
|
4946
|
-
|
|
4987
|
+
|
|
4988
|
+
// instance methods
|
|
4989
|
+
// getPaymentId() {
|
|
4990
|
+
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4991
|
+
// }
|
|
4992
|
+
addMetadata(key, value) {
|
|
4993
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, key, value)
|
|
4994
|
+
return this
|
|
4947
4995
|
}
|
|
4948
|
-
|
|
4949
|
-
|
|
4996
|
+
addRemark(key, value) {
|
|
4997
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, key, value)
|
|
4998
|
+
return this
|
|
4950
4999
|
}
|
|
4951
|
-
|
|
4952
|
-
|
|
5000
|
+
|
|
5001
|
+
compareStatus(paymentResult) {
|
|
5002
|
+
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4953
5003
|
}
|
|
4954
|
-
|
|
4955
|
-
|
|
5004
|
+
getPaidAmount() {
|
|
5005
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaidAmount`)
|
|
4956
5006
|
}
|
|
4957
|
-
|
|
4958
|
-
|
|
5007
|
+
getPaidTimestamp() {
|
|
5008
|
+
throw new Error(
|
|
5009
|
+
`${this.paymentResultType} subclass should implement getPaidTimestamp in milliseconds`
|
|
5010
|
+
)
|
|
4959
5011
|
}
|
|
4960
|
-
|
|
4961
|
-
|
|
5012
|
+
getPaymentCode() {
|
|
5013
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaymentCode`)
|
|
4962
5014
|
}
|
|
4963
|
-
|
|
4964
|
-
|
|
5015
|
+
getTransactionStatus() {
|
|
5016
|
+
throw new Error(`${this.paymentResultType} subclass should implement getTransactionStatus`)
|
|
4965
5017
|
}
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
const obj = {
|
|
4970
|
-
...this,
|
|
4971
|
-
...this.status,
|
|
4972
|
-
used: this.isUsed,
|
|
4973
|
-
productName: this.product && this.product.name ? this.product.name : ''
|
|
5018
|
+
handlePayment(payment) {
|
|
5019
|
+
if (!this.isForThisPayment(payment)) {
|
|
5020
|
+
return { payment, err: new Error('the payment result is not for this payment') }
|
|
4974
5021
|
}
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
5022
|
+
if (!this.isSameAmount(payment)) {
|
|
5023
|
+
return { payment, err: new Error('the amount was not matched') }
|
|
5024
|
+
}
|
|
5025
|
+
try {
|
|
5026
|
+
payment.settled()
|
|
5027
|
+
payment
|
|
5028
|
+
.setPaidAmount(this.getPaidAmount())
|
|
5029
|
+
.setPaidTimestamp(this.getPaidTimestamp())
|
|
5030
|
+
.setPaymentResultCode(this.paymentResultCode)
|
|
5031
|
+
return { payment, err: null }
|
|
5032
|
+
} catch (err) {
|
|
5033
|
+
return { payment, err }
|
|
4983
5034
|
}
|
|
4984
5035
|
}
|
|
4985
|
-
|
|
4986
|
-
return
|
|
4987
|
-
? (userId === this.owner)
|
|
4988
|
-
: false
|
|
4989
|
-
}
|
|
4990
|
-
setAssigned(value) {
|
|
4991
|
-
this.status.setAssigned(value)
|
|
4992
|
-
return this
|
|
5036
|
+
isForThisPayment(payment) {
|
|
5037
|
+
return this.getPaymentCode() === payment.paymentCode
|
|
4993
5038
|
}
|
|
4994
|
-
|
|
4995
|
-
this.
|
|
4996
|
-
return this
|
|
5039
|
+
isSameAmount(payment) {
|
|
5040
|
+
return this.getPaidAmount() === payment.getAmount()
|
|
4997
5041
|
}
|
|
4998
|
-
|
|
4999
|
-
this.
|
|
5000
|
-
return this
|
|
5042
|
+
isSuccess() {
|
|
5043
|
+
throw new Error(`${this.paymentResultType} subclass should implement isSuccess`)
|
|
5001
5044
|
}
|
|
5002
5045
|
setModified() {
|
|
5003
5046
|
this.modified = (new Date()).valueOf()
|
|
5004
5047
|
return this
|
|
5005
5048
|
}
|
|
5006
|
-
|
|
5007
|
-
this.
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
return this
|
|
5014
|
-
}
|
|
5015
|
-
setPending() {
|
|
5016
|
-
this.status.setPending()
|
|
5017
|
-
return this
|
|
5018
|
-
}
|
|
5019
|
-
setRedeemed() {
|
|
5020
|
-
this.status.setRedeemed()
|
|
5021
|
-
return this
|
|
5022
|
-
}
|
|
5023
|
-
setRejected() {
|
|
5024
|
-
this.status.setRejected()
|
|
5025
|
-
return this
|
|
5026
|
-
}
|
|
5027
|
-
setShared() {
|
|
5028
|
-
this.status.setShared()
|
|
5029
|
-
return this
|
|
5030
|
-
}
|
|
5031
|
-
setUsedTimestamp() {
|
|
5032
|
-
this.status.setUsed()
|
|
5033
|
-
// this.statusTimestamp.setUsed()
|
|
5049
|
+
setupMetadata() {
|
|
5050
|
+
const amount = this.amount
|
|
5051
|
+
const paymentMethod = this.paymentMethod
|
|
5052
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
5053
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
5054
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
5055
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
5034
5056
|
return this
|
|
5035
5057
|
}
|
|
5036
|
-
|
|
5037
|
-
this.
|
|
5038
|
-
return this
|
|
5058
|
+
setupRemarks() {
|
|
5059
|
+
return this.setupMetadata()
|
|
5039
5060
|
}
|
|
5040
|
-
// toTicket() {
|
|
5041
|
-
// return {
|
|
5042
|
-
// delivered: this.status.delivered,
|
|
5043
|
-
// eventRegistrationCode: this.eventRegistrationCode,
|
|
5044
|
-
// eventShortCode: this.eventShortCode,
|
|
5045
|
-
// name: this.product.name,
|
|
5046
|
-
// printLayoutCodes: this.product.printLayoutCodes,
|
|
5047
|
-
// productCategories: this.product.productCategories,
|
|
5048
|
-
// productCode: this.productCode,
|
|
5049
|
-
// settled: this.status.settled,
|
|
5050
|
-
// takenTime: this.statusTimestamp.delivered,
|
|
5051
|
-
// tenantCode: this.tenantCode,
|
|
5052
|
-
// waived: this.status.waived,
|
|
5053
|
-
// walletItemCode: this.walletItemCode
|
|
5054
|
-
// }
|
|
5055
|
-
// }
|
|
5056
5061
|
update(update) {
|
|
5057
5062
|
Object.keys(update).forEach((key) => {
|
|
5058
|
-
if (
|
|
5063
|
+
if (paymentResult_updateAllowedProps.includes(key)) {
|
|
5059
5064
|
if (key === 'metadata') {
|
|
5060
5065
|
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
5061
|
-
} else if (key === '
|
|
5066
|
+
} else if (key === 'remarks') {
|
|
5062
5067
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
5063
|
-
} else if (key === 'status') {
|
|
5064
|
-
this[key] = this._Status.init(update[key])
|
|
5065
5068
|
} else {
|
|
5066
5069
|
this[key] = update[key]
|
|
5067
5070
|
}
|
|
@@ -5071,14 +5074,7 @@ class WalletItem {
|
|
|
5071
5074
|
}
|
|
5072
5075
|
}
|
|
5073
5076
|
|
|
5074
|
-
function
|
|
5075
|
-
if (id && typeof id.toString === 'function') {
|
|
5076
|
-
return id.toString()
|
|
5077
|
-
}
|
|
5078
|
-
return id
|
|
5079
|
-
}
|
|
5080
|
-
|
|
5081
|
-
function walletItem_setCode(options, key) {
|
|
5077
|
+
function paymentResult_setCode(options, key) {
|
|
5082
5078
|
const copyOptions = options || {}
|
|
5083
5079
|
if (copyOptions[key]) {
|
|
5084
5080
|
return copyOptions[key]
|
|
@@ -5086,30 +5082,44 @@ function walletItem_setCode(options, key) {
|
|
|
5086
5082
|
return stringHelper.setCode()
|
|
5087
5083
|
}
|
|
5088
5084
|
|
|
5085
|
+
function paymentResult_setId(id) {
|
|
5086
|
+
if (id && typeof id.toString === 'function') {
|
|
5087
|
+
return id.toString()
|
|
5088
|
+
}
|
|
5089
|
+
return id
|
|
5090
|
+
}
|
|
5091
|
+
|
|
5089
5092
|
|
|
5090
5093
|
|
|
5091
|
-
;// ./lib/models/
|
|
5094
|
+
;// ./lib/models/paymentResult/paymentResultRepo.js
|
|
5092
5095
|
|
|
5093
5096
|
|
|
5094
5097
|
|
|
5095
|
-
class
|
|
5098
|
+
class PaymentResultRepo extends q_utilities_namespaceObject.Repo {
|
|
5096
5099
|
constructor(options = {}) {
|
|
5097
5100
|
options = options || {}
|
|
5098
5101
|
super(options)
|
|
5099
|
-
const {
|
|
5100
|
-
this.
|
|
5102
|
+
const { _PaymentResult } = options._constructor || {}
|
|
5103
|
+
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5101
5104
|
}
|
|
5102
5105
|
static get _classname() {
|
|
5103
|
-
return '
|
|
5106
|
+
return 'PaymentResultRepo'
|
|
5104
5107
|
}
|
|
5105
5108
|
init(options) {
|
|
5106
|
-
return this.
|
|
5109
|
+
return this._PaymentResult.init(options)
|
|
5107
5110
|
}
|
|
5108
5111
|
}
|
|
5109
5112
|
|
|
5110
5113
|
|
|
5111
5114
|
|
|
5112
|
-
;// ./lib/models/
|
|
5115
|
+
;// ./lib/models/paymentResult/index.js
|
|
5116
|
+
|
|
5117
|
+
|
|
5118
|
+
|
|
5119
|
+
|
|
5120
|
+
|
|
5121
|
+
|
|
5122
|
+
;// ./lib/models/status/index.js
|
|
5113
5123
|
|
|
5114
5124
|
|
|
5115
5125
|
|