mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 05:10:19 +08:00
Add InvoicePayment() API.
This commit is contained in:
@ -53,6 +53,7 @@ type Payment struct {
|
||||
InvoiceTitle string `xorm:"varchar(100)" json:"invoiceTitle"`
|
||||
InvoiceTaxId string `xorm:"varchar(100)" json:"invoiceTaxId"`
|
||||
InvoiceRemark string `xorm:"varchar(100)" json:"invoiceRemark"`
|
||||
InvoiceUrl string `xorm:"varchar(100)" json:"invoiceUrl"`
|
||||
}
|
||||
|
||||
func GetPaymentCount(owner, field, value string) int {
|
||||
@ -206,6 +207,46 @@ func NotifyPayment(request *http.Request, body []byte, owner string, providerNam
|
||||
return ok
|
||||
}
|
||||
|
||||
func invoicePayment(payment *Payment) (string, error) {
|
||||
provider := getProvider(payment.Owner, payment.Provider)
|
||||
if provider == nil {
|
||||
return "", fmt.Errorf("the payment provider: %s does not exist", payment.Provider)
|
||||
}
|
||||
|
||||
pProvider, _, err := provider.getPaymentProvider()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
invoiceUrl, err := pProvider.GetInvoice(payment.Name, payment.PersonName, payment.PersonIdCard, payment.PersonEmail, payment.PersonPhone, payment.InvoiceType, payment.InvoiceTitle, payment.InvoiceTaxId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return invoiceUrl, nil
|
||||
}
|
||||
|
||||
func InvoicePayment(payment *Payment) bool {
|
||||
if payment.State != "Paid" {
|
||||
return false
|
||||
}
|
||||
|
||||
invoiceUrl, err := invoicePayment(payment)
|
||||
|
||||
if err != nil {
|
||||
payment.State = "Error"
|
||||
payment.Message = err.Error()
|
||||
} else {
|
||||
payment.State = "Invoiced"
|
||||
payment.InvoiceUrl = invoiceUrl
|
||||
}
|
||||
|
||||
UpdatePayment(payment.GetId(), payment)
|
||||
|
||||
ok := err == nil
|
||||
return ok
|
||||
}
|
||||
|
||||
func (payment *Payment) GetId() string {
|
||||
return fmt.Sprintf("%s/%s", payment.Owner, payment.Name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user