private async Task PerformTest(UserType userType) { this.apiKeyRepository.Setup(v => v.GetApiKey(userType)).Returns(ApiKey); var expectedInput = new CreateRefundIn { Amount = AmountInMinorDenomination.Create(RefundCreditAmount).ToMajorDenomination(), CustomId = CreateTaxamoTransaction.CustomId }; CreateRefundIn actualInput = null; this.taxamoService.Setup(v => v.CreateRefundAsync(TaxamoTransactionKey, It.IsAny <CreateRefundIn>(), ApiKey)) .Callback <string, CreateRefundIn, string>((a, b, c) => actualInput = b) .ReturnsAsync(new CreateRefundOut { TotalAmount = 0.12m, TaxAmount = 0.02m, }); var result = await this.target.ExecuteAsync(TaxamoTransactionKey, RefundCreditAmount, userType); Assert.AreEqual( new CreateTaxamoRefund.TaxamoRefundResult( PositiveInt.Parse(12), NonNegativeInt.Parse(2)), result); Assert.AreEqual( JsonConvert.SerializeObject(expectedInput, Formatting.None), JsonConvert.SerializeObject(actualInput, Formatting.None)); }
public async Task <TaxamoRefundResult> ExecuteAsync( string taxamoTransactionKey, PositiveInt refundCreditAmount, UserType userType) { taxamoTransactionKey.AssertNotNull("taxamoTransactionKey"); refundCreditAmount.AssertNotNull("refundCreditAmount"); var amount = AmountInMinorDenomination.Create(refundCreditAmount).ToMajorDenomination(); var apiKey = this.taxamoApiKeyRepository.GetApiKey(userType); var input = new CreateRefundIn { Amount = amount, CustomId = CreateTaxamoTransaction.CustomId, }; var result = await this.taxamoService.CreateRefundAsync(taxamoTransactionKey, input, apiKey); var totalAmount = AmountInMinorDenomination.FromMajorDenomination(result.TotalAmount.Value); var taxAmount = AmountInMinorDenomination.FromMajorDenomination(result.TaxAmount.Value); return(new TaxamoRefundResult(totalAmount.ToPositiveInt(), taxAmount.ToNonNegativeInt())); }
public async Task <TaxamoCalculationResult> ExecuteAsync( PositiveInt amount, string billingCountryCode, string creditCardPrefix, string ipAddress, string originalTaxamoTransactionKey, UserType userType) { amount.AssertNotNull("amount"); var apiKey = this.taxamoApiKeyRepository.GetApiKey(userType); var input = new CalculateTaxIn { Transaction = new InputTransaction { CurrencyCode = PaymentConstants.Usd, TransactionLines = new List <InputTransactionLine> { new InputTransactionLine { CustomId = CreateTaxamoTransaction.CustomId, Amount = new AmountInMinorDenomination(amount.Value).ToMajorDenomination() } }, BuyerCreditCardPrefix = creditCardPrefix, BuyerIp = ipAddress, BillingCountryCode = billingCountryCode, OriginalTransactionKey = originalTaxamoTransactionKey } }; var result = await this.taxamoService.CalculateTaxAsync(input, apiKey); var countryDetected = this.IsCountryDetected(result); return(new TaxamoCalculationResult( result.Transaction.Amount == null ? null : AmountInMinorDenomination.FromMajorDenomination(result.Transaction.Amount.Value), result.Transaction.TotalAmount == null ? null : AmountInMinorDenomination.FromMajorDenomination(result.Transaction.TotalAmount.Value), result.Transaction.TaxAmount == null ? null : AmountInMinorDenomination.FromMajorDenomination(result.Transaction.TaxAmount.Value), result.Transaction.TransactionLines[0].TaxRate, result.Transaction.TransactionLines[0].TaxName, result.Transaction.TaxEntityName, countryDetected ? result.Transaction.CountryName : null, countryDetected ? null : this.GetPossibleCountries(result))); }
public async Task <string> ExecuteAsync( string stripeCustomerId, AmountInMinorDenomination amount, UserId userId, TransactionReference transactionReference, string taxamoTransactionKey, UserType userType) { stripeCustomerId.AssertNotNull("stripeCustomerId"); amount.AssertNotNull("amount"); userId.AssertNotNull("userId"); var apiKey = this.apiKeyRepository.GetApiKey(userType); var options = new StripeChargeCreateOptions { Amount = amount.Value, Currency = Currency, CustomerId = stripeCustomerId, Metadata = new Dictionary <string, string> { { TransactionReferenceMetadataKey, transactionReference.Value.ToString() }, { TaxamoTransactionKeyMetadataKey, taxamoTransactionKey }, { UserIdMetadataKey, userId.ToString() }, } }; try { var result = await this.stripeService.CreateChargeAsync(options, apiKey); return(result.Id); } catch (Exception t) { throw new StripeChargeFailedException(t); } }