示例#1
0
 /// <summary>
 /// Initializes an instance of <see cref="MelliGateway"/>.
 /// </summary>
 /// <param name="httpContextAccessor"></param>
 /// <param name="httpClientFactory"></param>
 /// <param name="accountProvider"></param>
 /// <param name="crypto"></param>
 /// <param name="gatewayOptions"></param>
 /// <param name="messageOptions"></param>
 public MelliGateway(
     IHttpContextAccessor httpContextAccessor,
     IHttpClientFactory httpClientFactory,
     IGatewayAccountProvider <MelliGatewayAccount> accountProvider,
     IMelliGatewayCrypto crypto,
     IOptions <MelliGatewayOptions> gatewayOptions,
     IOptions <MessagesOptions> messageOptions) : base(accountProvider)
 {
     _httpContextAccessor = httpContextAccessor;
     _httpClient          = httpClientFactory.CreateClient(this);
     _crypto         = crypto;
     _messageOptions = messageOptions;
     _gatewayOptions = gatewayOptions.Value;
 }
示例#2
0
        public static async Task <MelliCallbackResult> CreateCallbackResultAsync(
            InvoiceContext context,
            HttpRequest httpRequest,
            MelliGatewayAccount account,
            IMelliGatewayCrypto crypto,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var apiResponseCode = await httpRequest.TryGetParamAsAsync <int>("ResCode", cancellationToken).ConfigureAwaitFalse();

            if (!apiResponseCode.Exists || apiResponseCode.Value != SuccessCode)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Result = PaymentVerifyResult.Failed(messagesOptions.PaymentFailed)
                });
            }

            var apiToken = await httpRequest.TryGetParamAsync("Token", cancellationToken).ConfigureAwaitFalse();

            var apiOrderId = await httpRequest.TryGetParamAsAsync <long>("OrderId", cancellationToken).ConfigureAwaitFalse();

            if (!apiOrderId.Exists || apiOrderId.Value != context.Payment.TrackingNumber)
            {
                return(new MelliCallbackResult
                {
                    IsSucceed = false,
                    Token = apiToken.Value,
                    Result = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway)
                });
            }

            var signedData = crypto.Encrypt(account.TerminalKey, apiToken.Value);

            var dataToVerify = CreateVerifyObject(apiToken.Value, signedData);

            return(new MelliCallbackResult
            {
                IsSucceed = true,
                Token = apiToken.Value,
                JsonDataToVerify = dataToVerify
            });
        }
示例#3
0
        public static object CreateRequestData(Invoice invoice, MelliGatewayAccount account, IMelliGatewayCrypto crypto)
        {
            var data = $"{account.TerminalId};{invoice.TrackingNumber};{(long)invoice.Amount}";

            var signedData = crypto.Encrypt(account.TerminalKey, data);

            return(CreateRequestObject(
                       account.TerminalId,
                       account.MerchantId,
                       invoice.Amount,
                       signedData,
                       invoice.CallbackUrl,
                       invoice.TrackingNumber));
        }