403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/ilovecveti.ru/bitrix/js/sale/payment-pay/lib/src/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/ilovecveti.ru/bitrix/js/sale/payment-pay/lib/src/payment-process.js
import {EventEmitter} from 'main.core.events';
import {EventType} from 'sale.payment-pay.const';
import {VirtualForm} from './virtual-form';
import {AbstractBackendProvider} from './abstract-backend-provider';

export class PaymentProcess
{
	constructor(options)
	{
		this.options = options || {};

		this.backendProvider = this.option('backendProvider', null);

		if (!this.backendProvider || !this.backendProvider instanceof AbstractBackendProvider) {
			throw new Error('Invalid backend provider');
		}

		this.allowPaymentRedirect = this.option('allowPaymentRedirect', true);
	}

	/**
	 * @public
	 * @returns {void}
	 */
	start()
	{
		this.backendProvider.initiatePayment().then(() => {this.handleResponse()});
	}

	/**
	 * @private
	 */
	handleResponse()
	{
		if (this.backendProvider.isResponseSucceed())
		{
			const redirected = this.tryToRedirectUserOnPaymentGate();

			if (!redirected)
			{
				EventEmitter.emit(EventType.payment.success, this.backendProvider.getResponse());
			}
		}
		else
		{
			EventEmitter.emit(EventType.payment.error, this.backendProvider.getResponse());
		}
	}

	/**
	 * @private
	 * @returns {boolean}
	 */
	tryToRedirectUserOnPaymentGate()
	{
		const url = this.backendProvider.getPaymentGateUrl();
		const html = this.backendProvider.getPaymentFormHtml();

		if (this.allowPaymentRedirect)
		{
			if (url)
			{
				window.location.href = url;
				return true;
			}
			else if (html)
			{
				return this.tryToAutoSubmitHtmlChunk(html);
			}
		}
		return false;
	}

	/**
	 * @private
	 * @param {string} html
	 * @returns {boolean}
	 */
	tryToAutoSubmitHtmlChunk(html)
	{
		return VirtualForm.createFromHtml(html).submit();
	}

	/**
	 * @private
	 * @param {string} name
	 * @param {*} defaultValue
	 * @returns {*}
	 */
	option(name, defaultValue)
	{
		return this.options.hasOwnProperty(name) ? this.options[name] : defaultValue;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit