mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 21:30:24 +08:00
Add ExtendProductWithProviders().
This commit is contained in:
@ -16,7 +16,6 @@ import React from "react";
|
||||
import {Button, Descriptions, Spin} from "antd";
|
||||
import i18next from "i18next";
|
||||
import * as ProductBackend from "./backend/ProductBackend";
|
||||
import * as ProviderBackend from "./backend/ProviderBackend";
|
||||
import * as Setting from "./Setting";
|
||||
|
||||
class ProductBuyPage extends React.Component {
|
||||
@ -26,14 +25,12 @@ class ProductBuyPage extends React.Component {
|
||||
classes: props,
|
||||
productName: props.match?.params.productName,
|
||||
product: null,
|
||||
providers: [],
|
||||
isPlacingOrder: false,
|
||||
};
|
||||
}
|
||||
|
||||
UNSAFE_componentWillMount() {
|
||||
this.getProduct();
|
||||
this.getPaymentProviders();
|
||||
}
|
||||
|
||||
getProduct() {
|
||||
@ -45,15 +42,6 @@ class ProductBuyPage extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
getPaymentProviders() {
|
||||
ProviderBackend.getProviders("admin")
|
||||
.then((res) => {
|
||||
this.setState({
|
||||
providers: res.filter(provider => provider.category === "Payment"),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getProductObj() {
|
||||
if (this.props.product !== undefined) {
|
||||
return this.props.product;
|
||||
@ -86,32 +74,6 @@ class ProductBuyPage extends React.Component {
|
||||
return `${this.getCurrencySymbol(product)}${product?.price} (${this.getCurrencyText(product)})`;
|
||||
}
|
||||
|
||||
getProviders(product) {
|
||||
if (this.state.providers.length === 0 || product.providers.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let providerMap = {};
|
||||
this.state.providers.forEach(provider => {
|
||||
providerMap[provider.name] = provider;
|
||||
});
|
||||
|
||||
return product.providers.map(providerName => providerMap[providerName]);
|
||||
}
|
||||
|
||||
getPayUrl(product, provider) {
|
||||
if (product === null || provider === null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return `https://${provider.type}`;
|
||||
// if (provider.type === "WeChat") {
|
||||
// return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
|
||||
// } else if (provider.type === "GitHub") {
|
||||
// return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
|
||||
// }
|
||||
}
|
||||
|
||||
buyProduct(product, provider) {
|
||||
this.setState({
|
||||
isPlacingOrder: true,
|
||||
@ -176,12 +138,11 @@ class ProductBuyPage extends React.Component {
|
||||
if (product.state !== "Published") {
|
||||
return i18next.t("product:This product is currently not in sale.");
|
||||
}
|
||||
if (product.providers.length === 0) {
|
||||
if (product.providerObjs.length === 0) {
|
||||
return i18next.t("product:There is no payment channel for this product.");
|
||||
}
|
||||
|
||||
const providers = this.getProviders(product);
|
||||
return providers.map(provider => {
|
||||
return product.providerObjs.map(provider => {
|
||||
return this.renderProviderButton(provider, product);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user