Return invoiceUrl in invoice-payment API.

This commit is contained in:
Gucheng Wang
2022-04-28 15:07:57 +08:00
parent f5590c42f7
commit 9af9ead939
4 changed files with 10 additions and 10 deletions

View File

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

View File

@ -226,23 +226,23 @@ func invoicePayment(payment *Payment) (string, error) {
return invoiceUrl, nil return invoiceUrl, nil
} }
func InvoicePayment(payment *Payment) error { func InvoicePayment(payment *Payment) (string, error) {
if payment.State != "Paid" { 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) invoiceUrl, err := invoicePayment(payment)
if err != nil { if err != nil {
return err return "", err
} }
payment.InvoiceUrl = invoiceUrl payment.InvoiceUrl = invoiceUrl
affected := UpdatePayment(payment.GetId(), payment) affected := UpdatePayment(payment.GetId(), payment)
if !affected { 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 { func (payment *Payment) GetId() string {

View File

@ -80,7 +80,8 @@ class PaymentEditPage extends React.Component {
}); });
if (res.msg === "") { if (res.msg === "") {
Setting.showMessage("success", `Successfully invoiced`); Setting.showMessage("success", `Successfully invoiced`);
window.location.reload(); Setting.openLinkSafe(res.data);
this.getPayment();
} else { } else {
Setting.showMessage(res.msg.includes("成功") ? "info" : "error", res.msg); Setting.showMessage(res.msg.includes("成功") ? "info" : "error", res.msg);
} }
@ -364,7 +365,7 @@ class PaymentEditPage extends React.Component {
<Col span={22} > <Col span={22} >
{ {
this.state.payment.invoiceUrl === "" ? ( this.state.payment.invoiceUrl === "" ? (
<Button type={"primary"} onClick={() => { <Button type={"primary"} loading={this.state.isInvoiceLoading} onClick={() => {
const errorText = this.checkError(); const errorText = this.checkError();
if (errorText !== "") { if (errorText !== "") {
Setting.showMessage("error", errorText); Setting.showMessage("error", errorText);

View File

@ -17,7 +17,6 @@ import {Button, Descriptions, Spin} from "antd";
import i18next from "i18next"; import i18next from "i18next";
import * as ProductBackend from "./backend/ProductBackend"; import * as ProductBackend from "./backend/ProductBackend";
import * as ProviderBackend from "./backend/ProviderBackend"; import * as ProviderBackend from "./backend/ProviderBackend";
import * as Provider from "./auth/Provider";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
class ProductBuyPage extends React.Component { class ProductBuyPage extends React.Component {