Improve InvoicePayment() error handling.

This commit is contained in:
Gucheng Wang 2022-04-27 00:24:48 +08:00
parent e5c1f560c5
commit ea005aaf4d
11 changed files with 50 additions and 14 deletions

View File

@ -169,6 +169,9 @@ func (c *ApiController) InvoicePayment() {
id := c.Input().Get("id") id := c.Input().Get("id")
payment := object.GetPayment(id) payment := object.GetPayment(id)
c.Data["json"] = wrapActionResponse(object.InvoicePayment(payment)) err := object.InvoicePayment(payment)
c.ServeJSON() if err != nil {
c.ResponseError(err.Error())
}
c.ResponseOk()
} }

View File

@ -226,25 +226,23 @@ func invoicePayment(payment *Payment) (string, error) {
return invoiceUrl, nil return invoiceUrl, nil
} }
func InvoicePayment(payment *Payment) bool { func InvoicePayment(payment *Payment) error {
if payment.State != "Paid" { if payment.State != "Paid" {
return false return fmt.Errorf("the payment state is supposed to be: \"%s\", got: \"%s\"", "Paid", payment.State)
} }
invoiceUrl, err := invoicePayment(payment) invoiceUrl, err := invoicePayment(payment)
if err != nil { if err != nil {
payment.State = "Error" return err
payment.Message = err.Error()
} else {
payment.State = "Invoiced"
payment.InvoiceUrl = invoiceUrl
} }
UpdatePayment(payment.GetId(), payment) payment.InvoiceUrl = invoiceUrl
affected := UpdatePayment(payment.GetId(), payment)
if !affected {
return fmt.Errorf("failed to update the payment: %s", payment.Name)
}
ok := err == nil return nil
return ok
} }
func (payment *Payment) GetId() string { func (payment *Payment) GetId() string {

View File

@ -65,7 +65,24 @@ class PaymentEditPage extends React.Component {
} }
issueInvoice() { issueInvoice() {
alert("111") this.setState({
isModalVisible: false,
});
PaymentBackend.invoicePayment(this.state.payment.owner, this.state.paymentName)
.then((res) => {
if (res.msg === "") {
Setting.showMessage("success", `Successfully invoiced`);
this.setState({
paymentName: this.state.payment.name,
});
} else {
Setting.showMessage("error", res.msg);
}
})
.catch(error => {
Setting.showMessage("error", `Failed to connect to server: ${error}`);
});
} }
downloadInvoice() { downloadInvoice() {
@ -361,6 +378,10 @@ class PaymentEditPage extends React.Component {
} }
checkError() { checkError() {
if (this.state.payment.state !== "Paid") {
return i18next.t("payment:Please pay the order first!");
}
if (!Setting.isValidPersonName(this.state.payment.personName)) { if (!Setting.isValidPersonName(this.state.payment.personName)) {
return i18next.t("signup:Please input your real name!"); return i18next.t("signup:Please input your real name!");
} }

View File

@ -54,3 +54,10 @@ export function deletePayment(payment) {
body: JSON.stringify(newPayment), body: JSON.stringify(newPayment),
}).then(res => res.json()); }).then(res => res.json());
} }
export function invoicePayment(owner, name) {
return fetch(`${Setting.ServerUrl}/api/invoice-payment?id=${owner}/${encodeURIComponent(name)}`, {
method: "POST",
credentials: "include"
}).then(res => res.json());
}

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "Person phone - Tooltip", "Person phone - Tooltip": "Person phone - Tooltip",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.",
"Please click the below button to return to the original website": "Please click the below button to return to the original website", "Please click the below button to return to the original website": "Please click the below button to return to the original website",
"Please pay the order first!": "Please pay the order first!",
"Price": "Price", "Price": "Price",
"Price - Tooltip": "Price - Tooltip", "Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...", "Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "Person phone - Tooltip", "Person phone - Tooltip": "Person phone - Tooltip",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.",
"Please click the below button to return to the original website": "Please click the below button to return to the original website", "Please click the below button to return to the original website": "Please click the below button to return to the original website",
"Please pay the order first!": "Please pay the order first!",
"Price": "Price", "Price": "Price",
"Price - Tooltip": "Price - Tooltip", "Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...", "Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "Person phone - Tooltip", "Person phone - Tooltip": "Person phone - Tooltip",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.",
"Please click the below button to return to the original website": "Please click the below button to return to the original website", "Please click the below button to return to the original website": "Please click the below button to return to the original website",
"Please pay the order first!": "Please pay the order first!",
"Price": "Price", "Price": "Price",
"Price - Tooltip": "Price - Tooltip", "Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...", "Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "Person phone - Tooltip", "Person phone - Tooltip": "Person phone - Tooltip",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.",
"Please click the below button to return to the original website": "Please click the below button to return to the original website", "Please click the below button to return to the original website": "Please click the below button to return to the original website",
"Please pay the order first!": "Please pay the order first!",
"Price": "Price", "Price": "Price",
"Price - Tooltip": "Price - Tooltip", "Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...", "Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "Person phone - Tooltip", "Person phone - Tooltip": "Person phone - Tooltip",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.",
"Please click the below button to return to the original website": "Please click the below button to return to the original website", "Please click the below button to return to the original website": "Please click the below button to return to the original website",
"Please pay the order first!": "Please pay the order first!",
"Price": "Price", "Price": "Price",
"Price - Tooltip": "Price - Tooltip", "Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...", "Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "Person phone - Tooltip", "Person phone - Tooltip": "Person phone - Tooltip",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.",
"Please click the below button to return to the original website": "Please click the below button to return to the original website", "Please click the below button to return to the original website": "Please click the below button to return to the original website",
"Please pay the order first!": "Please pay the order first!",
"Price": "Price", "Price": "Price",
"Price - Tooltip": "Price - Tooltip", "Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...", "Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "缴费人本人的手机号", "Person phone - Tooltip": "缴费人本人的手机号",
"Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "请仔细检查下列发票信息,发票一经开具,无法退换。", "Please carefully check your invoice information. Once the invoice is issued, it cannot be withdrawn or modified.": "请仔细检查下列发票信息,发票一经开具,无法退换。",
"Please click the below button to return to the original website": "请点击下方按钮返回原网站", "Please click the below button to return to the original website": "请点击下方按钮返回原网站",
"Please pay the order first!": "请先完成支付后再进行操作!",
"Price": "价格", "Price": "价格",
"Price - Tooltip": "商品价格", "Price - Tooltip": "商品价格",
"Processing...": "正在处理...", "Processing...": "正在处理...",