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