From 9af9ead93992cc042d30afb456baffe9a70ef42f Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Thu, 28 Apr 2022 15:07:57 +0800 Subject: [PATCH] Return invoiceUrl in invoice-payment API. --- controllers/payment.go | 4 ++-- object/payment.go | 10 +++++----- web/src/PaymentEditPage.js | 5 +++-- web/src/ProductBuyPage.js | 1 - 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/controllers/payment.go b/controllers/payment.go index 18967c50..b3c7fb02 100644 --- a/controllers/payment.go +++ b/controllers/payment.go @@ -169,9 +169,9 @@ func (c *ApiController) InvoicePayment() { id := c.Input().Get("id") payment := object.GetPayment(id) - err := object.InvoicePayment(payment) + invoiceUrl, err := object.InvoicePayment(payment) if err != nil { c.ResponseError(err.Error()) } - c.ResponseOk() + c.ResponseOk(invoiceUrl) } diff --git a/object/payment.go b/object/payment.go index 167382e1..8db601a0 100644 --- a/object/payment.go +++ b/object/payment.go @@ -226,23 +226,23 @@ func invoicePayment(payment *Payment) (string, error) { return invoiceUrl, nil } -func InvoicePayment(payment *Payment) error { +func InvoicePayment(payment *Payment) (string, error) { if payment.State != "Paid" { - return fmt.Errorf("the payment state is supposed to be: \"%s\", got: \"%s\"", "Paid", payment.State) + return "", fmt.Errorf("the payment state is supposed to be: \"%s\", got: \"%s\"", "Paid", payment.State) } invoiceUrl, err := invoicePayment(payment) if err != nil { - return err + return "", err } payment.InvoiceUrl = invoiceUrl affected := UpdatePayment(payment.GetId(), payment) if !affected { - return fmt.Errorf("failed to update the payment: %s", payment.Name) + return "", fmt.Errorf("failed to update the payment: %s", payment.Name) } - return nil + return invoiceUrl, nil } func (payment *Payment) GetId() string { diff --git a/web/src/PaymentEditPage.js b/web/src/PaymentEditPage.js index 8093083c..e0025d34 100644 --- a/web/src/PaymentEditPage.js +++ b/web/src/PaymentEditPage.js @@ -80,7 +80,8 @@ class PaymentEditPage extends React.Component { }); if (res.msg === "") { Setting.showMessage("success", `Successfully invoiced`); - window.location.reload(); + Setting.openLinkSafe(res.data); + this.getPayment(); } else { Setting.showMessage(res.msg.includes("成功") ? "info" : "error", res.msg); } @@ -364,7 +365,7 @@ class PaymentEditPage extends React.Component { { this.state.payment.invoiceUrl === "" ? ( -