Skip to content

Commit

Permalink
Add payerName to provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeguy committed Apr 28, 2022
1 parent 5597f99 commit f5590c4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
3 changes: 2 additions & 1 deletion object/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ func BuyProduct(id string, providerName string, user *User, host string) (string

owner := product.Owner
productName := product.Name
payerName := fmt.Sprintf("%s | %s", user.Name, user.DisplayName)
paymentName := util.GenerateTimeId()
productDisplayName := product.DisplayName

originFrontend, originBackend := getOriginFromHost(host)
returnUrl := fmt.Sprintf("%s/payments/%s/result", originFrontend, paymentName)
notifyUrl := fmt.Sprintf("%s/api/notify-payment/%s/%s/%s/%s", originBackend, owner, providerName, productName, paymentName)

payUrl, err := pProvider.Pay(providerName, productName, paymentName, productDisplayName, product.Price, returnUrl, notifyUrl)
payUrl, err := pProvider.Pay(providerName, productName, payerName, paymentName, productDisplayName, product.Price, returnUrl, notifyUrl)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion pp/alipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewAlipayPaymentProvider(appId string, appPublicKey string, appPrivateKey s
return pp
}

func (pp *AlipayPaymentProvider) Pay(providerName string, productName string, paymentName string, productDisplayName string, price float64, returnUrl string, notifyUrl string) (string, error) {
func (pp *AlipayPaymentProvider) Pay(providerName string, productName string, payerName string, paymentName string, productDisplayName string, price float64, returnUrl string, notifyUrl string) (string, error) {
//pp.Client.DebugSwitch = gopay.DebugOn

bm := gopay.BodyMap{}
Expand Down
24 changes: 18 additions & 6 deletions pp/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ type GcPayReqInfo struct {
OrderDate string `json:"orderdate"`
OrderNo string `json:"orderno"`
Amount string `json:"amount"`
PayerId string `json:"payerid"`
PayerName string `json:"payername"`
Xmpch string `json:"xmpch"`
Body string `json:"body"`
ReturnUrl string `json:"return_url"`
NotifyUrl string `json:"notify_url"`
PayerId string `json:"payerid"`
PayerName string `json:"payername"`
Remark1 string `json:"remark1"`
Remark2 string `json:"remark2"`
}

type GcPayRespInfo struct {
Expand Down Expand Up @@ -151,16 +154,17 @@ func (pp *GcPaymentProvider) doPost(postBytes []byte) ([]byte, error) {
return respBytes, nil
}

func (pp *GcPaymentProvider) Pay(providerName string, productName string, paymentName string, productDisplayName string, price float64, returnUrl string, notifyUrl string) (string, error) {
func (pp *GcPaymentProvider) Pay(providerName string, productName string, payerName string, paymentName string, productDisplayName string, price float64, returnUrl string, notifyUrl string) (string, error) {
payReqInfo := GcPayReqInfo{
OrderDate: util.GenerateSimpleTimeId(),
OrderNo: util.GenerateTimeId(),
OrderNo: paymentName,
Amount: getPriceString(price),
PayerId: "",
PayerName: "",
Xmpch: pp.Xmpch,
Body: productDisplayName,
ReturnUrl: returnUrl,
NotifyUrl: notifyUrl,
Remark1: payerName,
Remark2: productName,
}

b, err := json.Marshal(payReqInfo)
Expand Down Expand Up @@ -316,5 +320,13 @@ func (pp *GcPaymentProvider) GetInvoice(paymentName string, personName string, p
return "", err
}

if invoiceRespInfo.State == "0" {
return "", fmt.Errorf("申请成功,开票中")
}

if invoiceRespInfo.Url == "" {
return "", fmt.Errorf("invoice URL is empty")
}

return invoiceRespInfo.Url, nil
}
2 changes: 1 addition & 1 deletion pp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package pp
import "net/http"

type PaymentProvider interface {
Pay(providerName string, productName string, paymentName string, productDisplayName string, price float64, returnUrl string, notifyUrl string) (string, error)
Pay(providerName string, productName string, payerName string, paymentName string, productDisplayName string, price float64, returnUrl string, notifyUrl string) (string, error)
Notify(request *http.Request, body []byte, authorityPublicKey string) (string, string, float64, string, string, error)
GetInvoice(paymentName string, personName string, personIdCard string, personEmail string, personPhone string, invoiceType string, invoiceTitle string, invoiceTaxId string) (string, error)
}
Expand Down
14 changes: 10 additions & 4 deletions web/src/PaymentEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PaymentEditPage extends React.Component {
paymentName: props.match.params.paymentName,
payment: null,
isModalVisible: false,
isInvoiceLoading: false,
mode: props.location.mode !== undefined ? props.location.mode : "edit",
};
}
Expand Down Expand Up @@ -69,20 +70,25 @@ class PaymentEditPage extends React.Component {
issueInvoice() {
this.setState({
isModalVisible: false,
isInvoiceLoading: true,
});

PaymentBackend.invoicePayment(this.state.payment.owner, this.state.paymentName)
.then((res) => {
this.setState({
isInvoiceLoading: false,
});
if (res.msg === "") {
Setting.showMessage("success", `Successfully invoiced`);
this.setState({
paymentName: this.state.payment.name,
});
window.location.reload();
} else {
Setting.showMessage("error", res.msg);
Setting.showMessage(res.msg.includes("成功") ? "info" : "error", res.msg);
}
})
.catch(error => {
this.setState({
isInvoiceLoading: false,
});
Setting.showMessage("error", `Failed to connect to server: ${error}`);
});
}
Expand Down
2 changes: 2 additions & 0 deletions web/src/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ export function showMessage(type, text) {
message.success(text);
} else if (type === "error") {
message.error(text);
} else if (type === "info") {
message.info(text);
}
}

Expand Down

0 comments on commit f5590c4

Please sign in to comment.