Пример #1
0
        public async Task<IActionResult> Details(string id)
        {
            var api = new PinchApi(_settings.SecretKey, _settings.MerchantId, false);

            var lineItems = await api.Transfer.GetLineItemsAll(id);

            return View(lineItems);
        }
Пример #2
0
        public async Task<IActionResult> Index()
        {
            var api = new PinchApi(_settings.SecretKey, _settings.MerchantId, false);

            var transfers = await api.Transfer.GetTransfers();

            return View(transfers);
        }
Пример #3
0
        // GET: /<controller>/
        public async Task<IActionResult> Index()
        {
            var api = new PinchApi(_settings.SecretKey, _settings.MerchantId);

            var payers = await api.Payer.GetPayers();

            return View(payers);
        }
Пример #4
0
        public async Task<IActionResult> GetAccessToken(string code)
        {
            var api = new PinchApi(_settings.SecretKey, _settings.MerchantId);

            var result = await api.Auth.GetAccessTokenFromCode(code, "app_123", "https://localhost:44389/pinch/callback");

            HttpContext.Session.SetObjectAsJson("AccessToken", result);

            return View("GetAccessToken", result);
        }
Пример #5
0
        public async Task <ServiceResponse <Merchant> > UpdateMerchant(string userId, bool isLive, string pinchMerchantId, string pinchSecretKey)
        {
            var response = new ServiceResponse <Merchant>();
            var user     = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId);

            if (string.IsNullOrEmpty(user.PinchMerchantId))
            {
                response.ErrorMessages.Add(new ValidationFailure("", "User does not have a merchant"));
                return(response);
            }
            if (string.IsNullOrEmpty(user.PinchPayerId))
            {
                response.ErrorMessages.Add(new ValidationFailure("paymentMethodMissing", "User does not have a payment method"));
                return(response);
            }

            var parentApi = new PinchApi(pinchMerchantId, pinchSecretKey, new PinchApiOptions()
            {
                IsLive = isLive
            });

            var managedApi = new PinchApi(user.PinchMerchantId, user.PinchMerchantSecretKey, new PinchApiOptions()
            {
                IsLive = isLive
            });

            var payer = await parentApi.Payer.Get(user.PinchPayerId);

            if (!payer.Success)
            {
                response.ErrorMessages.AddRange(payer.Errors.Select(x => new ValidationFailure(x.PropertyName, x.ErrorMessage)));
                return(response);
            }

            var merchantResponse = await managedApi.Merchant.UpdateMerchant(new MerchantUpdateOptions()
            {
                CompanyName   = $"BulkBuyd - {user.DisplayName}",
                StreetAddress = user.StreetAddress,
                Postcode      = user.Postcode,
                Suburb        = user.Suburb,
                Email         = user.Email,
                AccountName   = payer.Data.AccountName,
                AccountNumber = payer.Data.AccountNumber,
                BSB           = payer.Data.BSB
            });

            if (!merchantResponse.Success)
            {
                response.ErrorMessages.AddRange(merchantResponse.Errors.Select(x => new ValidationFailure(x.PropertyName, x.ErrorMessage)));
                return(response);
            }

            response.Data = merchantResponse.Data;
            return(response);
        }
Пример #6
0
        public async Task <Merchant> GetMerchant(string userId, bool isLive)
        {
            var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId);

            if (string.IsNullOrEmpty(user.PinchMerchantId))
            {
                return(null);
            }

            var api = new PinchApi(user.PinchMerchantId, user.PinchMerchantSecretKey, new PinchApiOptions()
            {
                IsLive = isLive
            });

            return(await api.Merchant.GetMerchant());
        }
Пример #7
0
        public async Task<IActionResult> Connect()
        {
            var token = HttpContext.Session.GetObjectFromJson<GetAccessTokenFromCodeResponse>("AccessToken");
            var model = new IndexVm()
            {
                AccessToken = token
            };

            if (!string.IsNullOrEmpty(model.AccessToken?.AccessToken))
            {
                var api = new PinchApi(_settings.SecretKey, _settings.MerchantId);
                var result = await api.Auth.GetClaims(model.AccessToken.AccessToken);
                model.Claims = result;
            }

            return View(model);
        }