Last active
January 29, 2023 14:18
-
-
Save ms314006/c85932264f8dda9e8b60c085e565105c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FailTransactionStatusDelegate { | |
constructor(transaction) { | |
this.statusString = '失敗'; | |
this.isNonRefundable = true; | |
} | |
} | |
export default FailTransactionStatusDelegate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PendingTransactionStatusDelegate { | |
constructor(transaction) { | |
this.statusString = '處理中'; | |
this.isNonRefundable = true; | |
} | |
} | |
export default PendingTransactionStatusDelegate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SuccessTransactioStatusnDelegate { | |
constructor(transaction) { | |
this.statusString = '成功'; | |
this.isNonRefundable = false; | |
} | |
} | |
export default SuccessTransactioStatusnDelegate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SuccessTransactioStatusnDelegate from './SuccessTransactioStatusnDelegate'; | |
import FailTransactionStatusDelegate from './FailTransactionStatusDelegate'; | |
import PendingTransactionStatusDelegate from './PendingTransactionStatusDelegate'; | |
class Transaction { | |
constructor(transaction) { | |
this.id = transaction.id; | |
this.transactionStatusDelegate = this.getTransactionStatusDelegate(transaction); | |
} | |
//... | |
getTransactionStatusDelegate(transaction) { | |
switch (transaction.status) { | |
case 'SUCCESS': | |
return new SuccessTransactioStatusnDelegate(transaction); | |
case 'FAIL': | |
return new FailTransactionStatusDelegate(transaction); | |
case 'PENDING': | |
return new PendingTransactionStatusDelegate(transaction); | |
default: | |
throw new Error(`Have no transaction status: ${transaction.status}`); | |
} | |
} | |
} | |
export default Transaction; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment