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

@ -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 {