private Request GetAuthsInternal(Authorization auth = null, Filter filter = null)
        {
            Dictionary <String, String> queryStr = new Dictionary <String, String>();

            if (auth != null && !String.IsNullOrWhiteSpace(auth.MerchantRefNum()))
            {
                queryStr.Add("merchantRefNum", auth.MerchantRefNum());
            }
            if (filter != null)
            {
                if (filter.Limit != null)
                {
                    queryStr.Add("limit", filter.Limit.ToString());
                }
                if (filter.Offset != null)
                {
                    queryStr.Add("offset", filter.Offset.ToString());
                }
                if (!String.IsNullOrWhiteSpace(filter.StartDate))
                {
                    queryStr.Add("startDate", filter.StartDate);
                }
                if (!String.IsNullOrWhiteSpace(filter.EndDate))
                {
                    queryStr.Add("endDate", filter.EndDate);
                }
            }

            return(new Request(
                       method: RequestType.Get,
                       uri: PrepareUri("/auths"),
                       queryString: queryStr
                       ));
        }
        public void When_I_void_an_auth_with_an_amount_too_large_Then_it_should_return_throw_RequestDeclinedException_async()
        {
            _auth = _cardService.Authorize(_auth);

            AuthorizationReversal authReversal = AuthorizationReversal.Builder()
                                                 .MerchantRefNum(_auth.MerchantRefNum())
                                                 .Amount(1000000) //Amount voided > authorized amount
                                                 .AuthorizationId(_auth.Id())
                                                 .Build();

            Assert.ThrowsAsync <Paysafe.Common.RequestDeclinedException>(async() => await _cardService.ReverseAuthAsync(authReversal));
        }
        public async Task When_I_settle_an_auth_Then_it_should_return_a_valid_response_async()
        {
            _auth = await _cardService.AuthorizeAsync(_auth);

            Settlement settle = Settlement.Builder()
                                .MerchantRefNum(_auth.MerchantRefNum())
                                .AuthorizationId(_auth.Id())
                                .Build();

            Settlement response = await _cardService.SettlementAsync(settle);

            Assert.That(response.Status(), Is.EqualTo("PENDING"));
        }
        public void When_I_lookup_an_auth_using_a_merchant_refNum_Then_it_should_return_a_valid_auth_sync()
        {
            _auth = _cardService.Authorize(_auth);

            Pagerator <Authorization> auths = _cardService.GetAuths(Authorization.Builder()
                                                                    .MerchantRefNum(_auth.MerchantRefNum())
                                                                    .Build());

            var authList = auths.GetResults();

            Assert.That(authList.Count, Is.EqualTo(1));
            Assert.That(AuthorizationsAreEquivalent(authList.First(), _auth));
        }
Esempio n. 5
0
        /// <summary>
        /// Get matching authorizations
        /// </summary>
        /// <param name="auth"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Pagerator <Authorization> GetAuths(Authorization auth = null, Filter filter = null)
        {
            Dictionary <String, String> queryStr = new Dictionary <String, String>();

            if (auth != null && !String.IsNullOrWhiteSpace(auth.MerchantRefNum()))
            {
                queryStr.Add("merchantRefNum", auth.MerchantRefNum());
            }
            if (filter != null)
            {
                if (filter.Limit != null)
                {
                    queryStr.Add("limit", filter.Limit.ToString());
                }
                if (filter.Offset != null)
                {
                    queryStr.Add("offset", filter.Offset.ToString());
                }
                if (!String.IsNullOrWhiteSpace(filter.StartDate))
                {
                    queryStr.Add("startDate", filter.StartDate);
                }
                if (!String.IsNullOrWhiteSpace(filter.EndDate))
                {
                    queryStr.Add("endDate", filter.EndDate);
                }
            }

            Request request = new Request(
                method: RequestType.Get,
                uri: PrepareUri("/auths"),
                queryString: queryStr
                );

            dynamic response = _client.ProcessRequest(request);

            return(new Pagerator <Authorization>(_client, typeof(Authorization), response));
        }
        public async Task When_I_partially_void_an_auth_Then_it_should_return_a_valid_response_async()
        {
            _auth = _cardService.Authorize(_auth);

            AuthorizationReversal authReversal = AuthorizationReversal.Builder()
                                                 .MerchantRefNum(_auth.MerchantRefNum())
                                                 .Amount(111) //Amount voided < authorized amount
                                                 .AuthorizationId(_auth.Id())
                                                 .Build();

            AuthorizationReversal response = await _cardService.ReverseAuthAsync(authReversal);

            Assert.That(response.Status(), Is.EqualTo("COMPLETED"));
        }
        public void When_I_void_an_auth_Then_it_should_return_a_valid_response_sync()
        {
            _auth = _cardService.Authorize(_auth);

            AuthorizationReversal authReversal = AuthorizationReversal.Builder()
                                                 .MerchantRefNum(_auth.MerchantRefNum())
                                                 .Amount(6666) // Amount voided == authorized amount
                                                 .AuthorizationId(_auth.Id())
                                                 .Build();

            AuthorizationReversal response = _cardService.ReverseAuth(authReversal);

            Assert.That(response.Status(), Is.EqualTo("COMPLETED"));
        }
        public async Task When_I_lookup_a_settlement_using_a_settlement_id_Then_it_should_return_a_valid_settlement_async()
        {
            _auth = await _cardService.AuthorizeAsync(_auth);

            Settlement settle = Settlement.Builder()
                                .MerchantRefNum(_auth.MerchantRefNum())
                                .AuthorizationId(_auth.Id())
                                .Build();

            settle = await _cardService.SettlementAsync(settle);

            var returnedSettle = await _cardService.GetAsync(new Settlement(settle.Id()));

            Assert.That(SettlementsAreEquivalent(settle, returnedSettle));
        }
        public void When_I_cancel_a_settlement_Then_it_should_return_a_valid_response_sync()
        {
            _auth = _cardService.Authorize(_auth);

            Settlement settle = Settlement.Builder()
                                .MerchantRefNum(_auth.MerchantRefNum())
                                .AuthorizationId(_auth.Id())
                                .Build();

            settle = _cardService.Settlement(settle);

            Settlement response = _cardService.CancelSettlement(settle);

            Assert.That(response.Status(), Is.EqualTo("CANCELLED"));
        }
        public void When_I_void_a_settled_auth_Then_it_should_return_throw_RequestDeclinedException_sync()
        {
            var service     = SampleFactory.CreateSampleCardPaymentService();
            var settledAuth = SampleFactory.CreateSampleSettledAuthorization();

            settledAuth = service.Authorize(settledAuth);

            AuthorizationReversal authReversal = AuthorizationReversal.Builder()
                                                 .MerchantRefNum(_auth.MerchantRefNum())
                                                 .Amount(6666) //Amount voided == authorized amount
                                                 .AuthorizationId(settledAuth.Id())
                                                 .Build();

            Assert.Throws <Paysafe.Common.RequestDeclinedException>(() => service.ReverseAuth(authReversal));
        }
        public async Task When_I_refund_a_pending_settlement_Then_it_should_throw_RequestDeclinedException_async()
        {
            _auth = await _cardService.AuthorizeAsync(_auth);

            Settlement settle = Settlement.Builder()
                                .MerchantRefNum(_auth.MerchantRefNum())
                                .AuthorizationId(_auth.Id())
                                .Build();

            settle = await _cardService.SettlementAsync(settle);

            Assert.ThrowsAsync <Paysafe.Common.RequestDeclinedException>(async() => await _cardService.RefundAsync(Refund.Builder()
                                                                                                                   .MerchantRefNum(settle.MerchantRefNum())
                                                                                                                   .SettlementId(settle.Id())
                                                                                                                   .Build()));
        }
        public void When_I_refund_a_pending_settlement_Then_it_should_throw_RequestDeclinedException_sync()
        {
            _auth = _cardService.Authorize(_auth);

            Settlement settle = Settlement.Builder()
                                .MerchantRefNum(_auth.MerchantRefNum())
                                .AuthorizationId(_auth.Id())
                                .Build();

            settle = _cardService.Settlement(settle);

            Assert.Throws <Paysafe.Common.RequestDeclinedException>(() => _cardService.Refund(Refund.Builder()
                                                                                              .MerchantRefNum(settle.MerchantRefNum())
                                                                                              .SettlementId(settle.Id())
                                                                                              .Build()));
        }
        public void When_I_lookup_a_reversal_using_a_reversal_id_Then_it_should_return_a_valid_reversal_sync()
        {
            _auth = _cardService.Authorize(_auth);

            AuthorizationReversal authReversal = AuthorizationReversal.Builder()
                                                 .MerchantRefNum(_auth.MerchantRefNum())
                                                 .Amount(6666)
                                                 .AuthorizationId(_auth.Id())
                                                 .Build();

            authReversal = _cardService.ReverseAuth(authReversal);

            AuthorizationReversal returnedReversal = _cardService.Get(new AuthorizationReversal(authReversal.Id()));

            Assert.That(returnedReversal.Status(), Is.EqualTo("COMPLETED"));
            Assert.That(AuthorizationReversalsAreEquivalent(authReversal, returnedReversal));
        }
        public async Task When_I_lookup_a_settlement_using_a_merchant_refNum_Then_it_should_return_a_valid_settlement_async()
        {
            _auth = await _cardService.AuthorizeAsync(_auth);

            Settlement settle = Settlement.Builder()
                                .MerchantRefNum(_auth.MerchantRefNum())
                                .AuthorizationId(_auth.Id())
                                .Build();

            settle = await _cardService.SettlementAsync(settle);

            Pagerator <Settlement> settlements = await _cardService.GetSettlementsAsync(Settlement.Builder()
                                                                                        .MerchantRefNum(settle.MerchantRefNum())
                                                                                        .Build());

            var settleList = settlements.GetResults();

            Assert.That(settleList.Count, Is.EqualTo(1));
            Assert.That(SettlementsAreEquivalent(settle, settleList.First()));
        }
        public async Task When_I_lookup_a_reversal_using_a_merchant_refNum_Then_it_should_return_a_valid_reversal_async()
        {
            _auth = await _cardService.AuthorizeAsync(_auth);

            AuthorizationReversal authReversal = AuthorizationReversal.Builder()
                                                 .MerchantRefNum(_auth.MerchantRefNum())
                                                 .Amount(6666)
                                                 .AuthorizationId(_auth.Id())
                                                 .Build();

            authReversal = await _cardService.ReverseAuthAsync(authReversal);

            Pagerator <AuthorizationReversal> authReversals = await _cardService.GetAuthReversalsAsync(AuthorizationReversal.Builder()
                                                                                                       .MerchantRefNum(authReversal.MerchantRefNum())
                                                                                                       .Build());


            var authRevList = authReversals.GetResults();

            Assert.That(authRevList.Count, Is.EqualTo(1));
            Assert.That(AuthorizationReversalsAreEquivalent(authReversal, authRevList[0]));
        }