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")
payment := object.GetPayment(id)
c.Data["json"] = wrapActionResponse(object.InvoicePayment(payment))
c.ServeJSON()
err := object.InvoicePayment(payment)
if err != nil {
c.ResponseError(err.Error())
}
c.ResponseOk()
}

View File

@ -226,25 +226,23 @@ func invoicePayment(payment *Payment) (string, error) {
return invoiceUrl, nil
}
func InvoicePayment(payment *Payment) bool {
func InvoicePayment(payment *Payment) error {
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)
if err != nil {
payment.State = "Error"
payment.Message = err.Error()
} else {
payment.State = "Invoiced"
payment.InvoiceUrl = invoiceUrl
return err
}
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 ok
return nil
}
func (payment *Payment) GetId() string {

View File

@ -65,7 +65,24 @@ class PaymentEditPage extends React.Component {
}
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() {
@ -361,6 +378,10 @@ class PaymentEditPage extends React.Component {
}
checkError() {
if (this.state.payment.state !== "Paid") {
return i18next.t("payment:Please pay the order first!");
}
if (!Setting.isValidPersonName(this.state.payment.personName)) {
return i18next.t("signup:Please input your real name!");
}

View File

@ -54,3 +54,10 @@ export function deletePayment(payment) {
body: JSON.stringify(newPayment),
}).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",
"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!": "Please pay the order first!",
"Price": "Price",
"Price - Tooltip": "Price - Tooltip",
"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!": "Please pay the order first!",
"Price": "Price",
"Price - Tooltip": "Price - Tooltip",
"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!": "Please pay the order first!",
"Price": "Price",
"Price - Tooltip": "Price - Tooltip",
"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!": "Please pay the order first!",
"Price": "Price",
"Price - Tooltip": "Price - Tooltip",
"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!": "Please pay the order first!",
"Price": "Price",
"Price - Tooltip": "Price - Tooltip",
"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!": "Please pay the order first!",
"Price": "Price",
"Price - Tooltip": "Price - Tooltip",
"Processing...": "Processing...",

View File

@ -291,6 +291,7 @@
"Person phone - Tooltip": "缴费人本人的手机号",
"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 pay the order first!": "请先完成支付后再进行操作!",
"Price": "价格",
"Price - Tooltip": "商品价格",
"Processing...": "正在处理...",