示例#1
0
        public async Task UpdatePaymentChangeTransactionState()
        {
            var oldState          = TransactionState.Initial;
            var newState          = TransactionState.Success;
            var refundTransaction = new TransactionDraft
            {
                Amount        = Money.FromDecimal("EUR", TestingUtility.RandomInt(100, 10000)),
                Type          = TransactionType.Refund,
                Timestamp     = DateTime.Now,
                State         = oldState,
                InteractionId = TestingUtility.RandomString()
            };

            await WithUpdateablePayment(client,
                                        paymentDraft => DefaultPaymentDraftWithTransaction(paymentDraft, refundTransaction),
                                        async payment =>
            {
                Assert.Single(payment.Transactions);
                Assert.Equal(oldState, payment.Transactions[0].State);
                var action = new ChangeTransactionStateUpdateAction
                {
                    TransactionId = payment.Transactions[0].Id,
                    State         = newState
                };

                var updatedPayment = await client
                                     .ExecuteAsync(payment.UpdateById(actions => actions.AddUpdate(action)));

                Assert.Single(updatedPayment.Transactions);
                Assert.Equal(newState, updatedPayment.Transactions[0].State);
                return(updatedPayment);
            });
        }
        public void UpdatePaymentChangeTransactionState()
        {
            IClient commerceToolsClient = this.paymentsFixture.GetService <IClient>();
            var     payment             = this.paymentsFixture.CreatePaymentWithTransaction();

            Assert.Single(payment.Transactions);

            var refundTransaction = payment.Transactions[0];

            ChangeTransactionStateUpdateAction changeTransactionStateUpdateAction = new ChangeTransactionStateUpdateAction()
            {
                TransactionId = new Guid(refundTransaction.Id),
                State         = TransactionState.Success
            };
            var updateActions = new List <UpdateAction <Payment> > {
                changeTransactionStateUpdateAction
            };

            var retrievedPayment = commerceToolsClient
                                   .ExecuteAsync(new UpdateByIdCommand <Payment>(payment.Id, payment.Version, updateActions))
                                   .Result;

            this.paymentsFixture.PaymentsToDelete.Add(retrievedPayment);

            Assert.Single(retrievedPayment.Transactions);
            Assert.NotEqual(refundTransaction.State, retrievedPayment.Transactions[0].State);
            Assert.Equal(TransactionState.Success, retrievedPayment.Transactions[0].State);
        }