webapp/src/components/Discours/Donate.tsx

182 lines
7.2 KiB
TypeScript
Raw Normal View History

2022-10-07 19:35:53 +00:00
import '../../styles/help.scss'
2022-09-09 11:53:35 +00:00
import { createSignal, onMount } from 'solid-js'
import { showModal, warn } from '../../stores/ui'
2023-02-17 09:21:02 +00:00
import { useLocalize } from '../../context/localize'
2022-09-09 11:53:35 +00:00
export const Donate = () => {
2023-02-17 09:21:02 +00:00
const { t } = useLocalize()
2022-09-09 11:53:35 +00:00
const once = ''
const monthly = 'Monthly'
const cpOptions = {
publicId: 'pk_0a37bab30ffc6b77b2f93d65f2aed',
2022-10-07 19:35:53 +00:00
description: t('Help discours to grow'),
2022-09-09 11:53:35 +00:00
currency: 'RUB'
}
let amountSwitchElement: HTMLDivElement | undefined
let customAmountElement: HTMLInputElement | undefined
2022-10-07 19:35:53 +00:00
const [widget, setWidget] = createSignal()
const [customerReciept, setCustomerReciept] = createSignal({})
2022-09-09 11:53:35 +00:00
const [showingPayment, setShowingPayment] = createSignal<boolean>()
const [period, setPeriod] = createSignal(monthly)
const [amount, setAmount] = createSignal(0)
2022-11-10 17:04:39 +00:00
const initiated = () => {
2022-10-08 16:40:58 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-10-07 19:35:53 +00:00
const {
cp: { CloudPayments }
} = window as any // Checkout(cpOptions)
setWidget(new CloudPayments())
2022-09-09 11:53:35 +00:00
console.log('[donate] payments initiated')
2022-10-07 19:35:53 +00:00
setCustomerReciept({
2022-09-09 11:53:35 +00:00
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 знака после запятой)
}
2022-10-07 19:35:53 +00:00
})
2022-11-10 17:04:39 +00:00
}
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
2022-11-13 06:41:04 +00:00
script.addEventListener('load', initiated)
2022-11-10 17:04:39 +00:00
document.head.appendChild(script)
2022-09-09 11:53:35 +00:00
})
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)
2022-10-08 16:40:58 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-10-07 19:35:53 +00:00
;(widget() as any).charge(
2022-09-09 11:53:35 +00:00
{
// options
...cpOptions,
amount: amount(),
skin: 'classic',
requireEmail: true,
retryPayment: true,
// invoiceId: '1234567', //номер заказа (необязательно)
// accountId: 'user@example.com', //идентификатор плательщика (обязательно для создания подписки)
data: {
CloudPayments: {
2022-10-07 19:35:53 +00:00
CustomerReciept: customerReciept(),
2022-09-09 11:53:35 +00:00
recurrent: {
interval: period(), // local solid's signal
period: 1, // internal widget's
2022-10-07 19:35:53 +00:00
CustomerReciept: customerReciept() // чек для регулярных платежей
2022-09-09 11:53:35 +00:00
}
}
}
},
2022-10-08 16:40:58 +00:00
(opts) => {
2022-09-09 11:53:35 +00:00
// success
// действие при успешной оплате
console.debug('[donate] options', opts)
showModal('thank')
},
2022-10-08 16:40:58 +00:00
function (reason: string, options) {
2022-09-09 11:53:35 +00:00
// fail
// действие при неуспешной оплате
console.debug('[donate] options', options)
warn({
kind: 'error',
body: reason,
seen: false
})
}
)
}
return (
2022-11-10 17:04:39 +00:00
<form class="discours-form donate-form" action="" method="post">
<input type="hidden" name="shopId" value="156465" />
<input value="148805" name="scid" type="hidden" />
<input value="0" name="customerNumber" type="hidden" />
2022-09-09 11:53:35 +00:00
2022-11-10 17:04:39 +00:00
<div class="form-group">
<div class="donate-buttons-container" ref={amountSwitchElement}>
<input type="radio" name="amount" id="fix250" value="250" />
<label for="fix250" class="btn donate-value-radio">
250&thinsp;
</label>
<input type="radio" name="amount" id="fix500" value="500" checked />
<label for="fix500" class="btn donate-value-radio">
500&thinsp;
</label>
<input type="radio" name="amount" id="fix1000" value="1000" />
<label for="fix1000" class="btn donate-value-radio">
1000&thinsp;
</label>
<input
class="form-control donate-input"
required
ref={customAmountElement}
type="number"
name="sum"
placeholder={t('Another amount')}
/>
2022-09-09 11:53:35 +00:00
</div>
2022-11-10 17:04:39 +00:00
</div>
2022-09-09 11:53:35 +00:00
2022-11-10 17:04:39 +00:00
<div class="form-group" id="payment-type" classList={{ showing: showingPayment() }}>
<div class="btn-group payment-choose" data-toggle="buttons">
<input
type="radio"
autocomplete="off"
id="once"
name="once"
onClick={() => setPeriod(once)}
checked={period() === once}
/>
<label for="once" class="btn payment-type" classList={{ active: period() === once }}>
{t('One time')}
</label>
<input
type="radio"
autocomplete="off"
id="monthly"
name="monthly"
onClick={() => setPeriod(monthly)}
checked={period() === monthly}
/>
<label for="monthly" class="btn payment-type" classList={{ active: period() === monthly }}>
{t('Every month')}
</label>
2022-09-09 11:53:35 +00:00
</div>
2022-11-10 17:04:39 +00:00
</div>
2022-09-09 11:53:35 +00:00
2022-11-10 17:04:39 +00:00
<div class="form-group">
<a href={''} class="btn send-btn donate" onClick={show}>
{t('Help discours to grow')}
</a>
</div>
</form>
2022-09-09 11:53:35 +00:00
)
}