UNPKG

pay-sdk-react

Version:

A cross-platform payment SDK for React, supporting Alipay, WeChat Pay, PayPal, Stripe, Payssion, and Airwallex, compatible with H5, PC, and App environments.

42 lines (38 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); const MAlipayAutoSubmit = ({ formHtml }) => { (0, _react.useEffect)(() => { // 1. 移除之前的表单 const oldForm = document.getElementById('alipaysubmit'); if (oldForm && oldForm.parentNode) { oldForm.parentNode.removeChild(oldForm); } // 2. 创建一个 div 容器,插入 form 字符串 const div = document.createElement('div'); div.innerHTML = formHtml; // 3. 获取 form 元素 const form = div.querySelector('form#alipaysubmit'); if (form) { form.acceptCharset = 'UTF-8'; document.body.appendChild(form); setTimeout(() => { form.submit(); }, 100); } // 4. 卸载时 return () => { const existForm = document.getElementById('alipaysubmit'); if (existForm && existForm.parentNode) { existForm.parentNode.removeChild(existForm); } }; }, [formHtml]); return null; // 这个组件不渲染任何内容 }; var _default = exports.default = /*#__PURE__*/(0, _react.memo)(MAlipayAutoSubmit);