This commit is contained in:
zadit
2025-02-21 07:17:46 +07:00
parent f1247dd11c
commit 43ad59a1f8
5 changed files with 47 additions and 31 deletions

View File

@@ -26,31 +26,32 @@ const CreateCouponPage = () => {
const [codeExpectation, setCodeExpectation] = useState('');
const [couponUrl, setCouponUrl] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
// Call the helper function to create the coupon
const result = await createCoupon(discountType, discountValue, discountPeriods, codeExpectation);
if (result.success) {
setCouponDetails(result.coupon);
const secretKey = 'xixixi666'; // AES-256 key (32 characters)
// Encrypt the coupon code inline
const encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString();
// Convert the encrypted code to Base64 URL-safe encoding
const base64UrlSafe = encryptedCouponCode.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
// Store the Base64 URL-safe encrypted coupon code in the query parameter
const encodedCouponCode = encodeURIComponent(base64UrlSafe); // Ensure it's safely encoded for URL use
const urlWithCoupon = `https://dev.coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
// Encrypt the coupon code inline using CryptoJS
let encryptedCouponCode = CryptoJS.AES.encrypt(result.coupon.code, secretKey).toString().replace('+','LDNWAlASJDNdaw').replace('/','XCLZBKlaWDJ').replace('=','LDSsadANJlas');
// Encode the encrypted coupon code for URL usage:
// 1. First, encodeURIComponent to handle URL-specific characters.
// 2. Then, replace special characters like '+' and '/' that might cause issues.
let encodedCouponCode = encodeURIComponent(encryptedCouponCode);
// Construct the URL with the encoded coupon code as a query parameter
const urlWithCoupon = `https://coupon.kedaimaster.com/coupon?c=${encodedCouponCode}`;
// Optionally, set the URL to use with the coupon
setCouponUrl(urlWithCoupon);
console.log(urlWithCoupon);
console.log("Generated URL with Encrypted Coupon Code:", urlWithCoupon);
setLoading(false);
} else {
setLoading(false);
@@ -58,6 +59,8 @@ const CreateCouponPage = () => {
};
return (
<div className={styles.linktreePage}>