import '../../styles/help.scss' import { createSignal, onMount } from 'solid-js' import { showModal, warn } from '../../stores/ui' import { t } from '../../utils/intl' export const Donate = () => { const once = '' const monthly = 'Monthly' const cpOptions = { publicId: 'pk_0a37bab30ffc6b77b2f93d65f2aed', description: t('Help discours to grow'), currency: 'RUB' } let amountSwitchElement: HTMLDivElement | undefined let customAmountElement: HTMLInputElement | undefined const [widget, setWidget] = createSignal() const [customerReciept, setCustomerReciept] = createSignal({}) const [showingPayment, setShowingPayment] = createSignal() const [period, setPeriod] = createSignal(monthly) const [amount, setAmount] = createSignal(0) const initiated = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const { cp: { CloudPayments } } = window as any // Checkout(cpOptions) setWidget(new CloudPayments()) console.log('[donate] payments initiated') setCustomerReciept({ Items: [ //товарные позиции { label: cpOptions.description, //наименование товара price: amount() || 0, //цена quantity: 1, //количество amount: amount() || 0, //сумма vat: 20, //ставка НДС method: 0, // тег-1214 признак способа расчета - признак способа расчета object: 0 // тег-1212 признак предмета расчета - признак предмета товара, работы, услуги, платежа, выплаты, иного предмета расчета } ], // taxationSystem: 0, //система налогообложения; необязательный, если у вас одна система налогообложения // email: 'user@example.com', //e-mail покупателя, если нужно отправить письмо с чеком // phone: '', //телефон покупателя в любом формате, если нужно отправить сообщение со ссылкой на чек isBso: false, //чек является бланком строгой отчетности amounts: { electronic: amount(), // Сумма оплаты электронными деньгами advancePayment: 0, // Сумма из предоплаты (зачетом аванса) (2 знака после запятой) credit: 0, // Сумма постоплатой(в кредит) (2 знака после запятой) provision: 0 // Сумма оплаты встречным предоставлением (сертификаты, др. мат.ценности) (2 знака после запятой) } }) } onMount(() => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const script = document.createElement('script') script.type = 'text/javascript' script.src = 'https://widget.cloudpayments.ru/bundles/cloudpayments.js' script.async = true script.onload = initiated document.head.appendChild(script) }) const show = () => { // $openModal = 'donate' setShowingPayment(true) console.log('[donate] clicked') const choice: HTMLInputElement | undefined | null = amountSwitchElement?.querySelector('input[type=radio]:checked') setAmount(Number.parseInt(customAmountElement?.value || choice?.value || '0')) console.log('[donate] input amount ' + amount) // eslint-disable-next-line @typescript-eslint/no-explicit-any ;(widget() as any).charge( { // options ...cpOptions, amount: amount(), skin: 'classic', requireEmail: true, retryPayment: true, // invoiceId: '1234567', //номер заказа (необязательно) // accountId: 'user@example.com', //идентификатор плательщика (обязательно для создания подписки) data: { CloudPayments: { CustomerReciept: customerReciept(), recurrent: { interval: period(), // local solid's signal period: 1, // internal widget's CustomerReciept: customerReciept() // чек для регулярных платежей } } } }, (opts) => { // success // действие при успешной оплате console.debug('[donate] options', opts) showModal('thank') }, function (reason: string, options) { // fail // действие при неуспешной оплате console.debug('[donate] options', options) warn({ kind: 'error', body: reason, seen: false }) } ) } return ( ) }