コード例 #1
0
        public async Task <GenerateTokenResponse> GenerateBuyToken(ulong amountInRials, string callbackURL, string paymentId = null, string mobileNumber = null)
        {
            var request = new GenerateTokenRequest(_config.MerchantConfigurationId, await _localInvoiceIdGenerator.GetNext(), amountInRials, callbackURL);

            if (!string.IsNullOrWhiteSpace(mobileNumber))
            {
                request.SetMobileNumber(mobileNumber);
            }
            if (!string.IsNullOrWhiteSpace(paymentId))
            {
                request.SetPaymentId(paymentId);
            }
            return(await GenerateToken(request));
        }
コード例 #2
0
        public async Task <IActionResult> PayCustom(PayCustomViewModel data)
        {
            try
            {
                var config = data.Config;
                config.GatewayUrl   = _config.CurrentValue.GatewayUrl;
                config.RestEndpoint = _config.CurrentValue.RestEndpoint;

                var client  = new AsanPardakht.IPG.Client(config);
                var service = new AsanPardakht.IPG.Services(client, config);
                var localInvoiceIdGenerator = new AsanPardakht.IPG.DefaultLocalInvoiceIdGenerator();
                var id = await localInvoiceIdGenerator.GetNext();

                var tokenRequest = new GenerateTokenRequest(config.MerchantConfigurationId, id, data.Amount, GenerateCallbackUrl(Request));

                tokenRequest.SetPaymentId(data.PaymentId);
                tokenRequest.SetServiceType(data.ServiceTypeId);
                tokenRequest.SetMobileNumber(data.Mobile);

                if (data.AdditionalData != null && data.AdditionalData.Any())
                {
                    foreach (var item in data.AdditionalData)
                    {
                        tokenRequest.AddAdditionalData(item.Key, item.Value);
                    }
                }

                if (data.SettlementPortions != null && data.SettlementPortions.Any())
                {
                    foreach (var item in data.SettlementPortions)
                    {
                        tokenRequest.AddSettlementPortion(new SettlementPortion(item.IBAN, item.AmountInRials, item.PaymentId));
                    }
                }

                var tokenModel = await service.GenerateToken(tokenRequest);

                return(View("Pay", tokenModel));
            }
            catch (Exception exc)
            {
                return(View("Error", new ErrorViewModel
                {
                    Message = exc.Message
                }));
            }
        }