Exemplo n.º 1
0
        static Guid?CreateTransactionExample(Configuration configuration)
        {
            TransactionsApi api = new TransactionsApi(configuration);

            // Please check our documentation at https://docs.transferzero.com/docs/transaction-flow/
            // for details on how transactions work

            // When adding a sender to transaction, please use either an id or external_id. Providing both will result in a validation error.
            // Please see our documentation at https://docs.transferzero.com/docs/transaction-flow/#sender

            Sender sender = new Sender(id: Guid.Parse("058de445-ffff-ffff-ffff-da9c751d14bf"));

            // You can find the various payout options at https://docs.transferzero.com/docs/transaction-flow/#payout-details

            PayoutMethodDetails ngnBankDetails = new PayoutMethodDetails(
                bankAccount: "123456789",
                bankAccountType: PayoutMethodBankAccountTypeEnum._20,
                bankCode: "082",
                firstName: "First",
                lastName: "Last"
                );

            PayoutMethod payoutMethod = new PayoutMethod(
                type: "NGN::Bank",
                details: ngnBankDetails
                );

            // Please see https://docs.transferzero.com/docs/transaction-flow/#requested-amount-and-currency
            // on what the request amount and currencies do

            Recipient recipient = new Recipient(
                requestedAmount: 10000,
                requestedCurrency: "NGN",
                payoutMethod: payoutMethod
                );

            // Similarly you can check https://docs.transferzero.com/docs/transaction-flow/#requested-amount-and-currency
            // on details about the input currency parameter

            // Find more details on external IDs at https://docs.transferzero.com/docs/transaction-flow/#external-id

            Transaction transaction = new Transaction(
                inputCurrency: "USD",
                sender: sender,
                recipients: new List <Recipient>()
            {
                recipient
            },
                externalId: "TRANSACTION-00001"
                );

            try
            {
                TransactionRequest transactionRequest = new TransactionRequest(
                    transaction: transaction
                    );
                TransactionResponse transactionResponse = api.PostTransactions(transactionRequest);
                System.Console.WriteLine("Transaction created! ID" + transactionResponse.Object.Id);
                System.Console.WriteLine(transactionResponse.Object);
                return(transactionResponse.Object.Id);
            }
            catch (ApiException e)
            {
                if (e.IsValidationError)
                {
                    TransactionResponse transactionResponse = e.ParseObject <TransactionResponse>();
                    System.Console.WriteLine("Validation Error" + transactionResponse.Object.Errors);
                }
                else
                {
                    throw e;
                }
                return(null);
            }
        }