private Transaction CreditAuth(decimal amount) { CreditTrackData track = TestCards.VisaSwipe(); AuthorizationBuilder builder = track.Authorize(amount) .WithCurrency("USD"); if (configName.Equals("NoBatch")) { builder.WithBatchNumber(batchProvider.GetBatchNumber(), batchProvider.GetSequenceNumber()); } Transaction response = builder.Execute(configName); Assert.IsNotNull(response); Assert.AreEqual("000", response.ResponseCode); Transaction capture = response.Capture().Execute(); Assert.IsNotNull(capture); System.Diagnostics.Debug.WriteLine("Auth Capture:"); System.Diagnostics.Debug.WriteLine(capture.HostResponseDate); System.Diagnostics.Debug.WriteLine(capture.SystemTraceAuditNumber); Assert.AreEqual("000", capture.ResponseCode); return(capture); }
private Transaction DebitSale(double amount) { DebitTrackData track = TestCards.AsDebit(TestCards.VisaSwipe(), "32539F50C245A6A93D123412324000AA"); AuthorizationBuilder builder = track.Charge(new decimal(amount)) .WithCurrency("USD"); if (configName.Equals("NoBatch")) { builder.WithBatchNumber(batchProvider.GetBatchNumber(), batchProvider.GetSequenceNumber()); } Transaction response = builder.Execute(configName); Assert.IsNotNull(response); Assert.AreEqual("000", response.ResponseCode); return(response); }
private Transaction CreditReturn(decimal amount, bool useExpiredCard = false) { CreditTrackData track = useExpiredCard ? TestCards.VisaSwipeExpired() : TestCards.VisaSwipe(); AuthorizationBuilder builder = track.Refund(amount) .WithCurrency("USD"); if (configName.Equals("NoBatch")) { builder.WithBatchNumber(batchProvider.GetBatchNumber(), batchProvider.GetSequenceNumber()); } Transaction response = builder.Execute(configName); Assert.IsNotNull(response); System.Diagnostics.Debug.WriteLine("Return:"); System.Diagnostics.Debug.WriteLine(response.HostResponseDate); System.Diagnostics.Debug.WriteLine(response.SystemTraceAuditNumber); return(response); }
public string Tokenize(bool validateCard, Address billingAddress, Customer customerData, string configName = "default") { TransactionType type = validateCard ? TransactionType.Verify : TransactionType.Tokenize; var builder = new AuthorizationBuilder(type, this) .WithRequestMultiUseToken(validateCard) .WithPaymentMethodUsageMode(PaymentMethodUsageMode.Multiple); if (billingAddress != null) { builder = builder.WithAddress(billingAddress); } if (customerData != null) { builder = builder.WithCustomerData(customerData); } var response = builder.Execute(configName); return(response.Token); }
private Transaction CreditAuth(double amount) { CreditTrackData track = TestCards.VisaSwipe(); AuthorizationBuilder builder = track.Authorize(new decimal(amount)) .WithCurrency("USD"); if (configName.Equals("NoBatch")) { builder.WithBatchNumber(batchProvider.GetBatchNumber(), batchProvider.GetSequenceNumber()); } Transaction response = builder.Execute(configName); Assert.IsNotNull(response); Assert.AreEqual("000", response.ResponseCode); Transaction capture = response.Capture().Execute(); Assert.IsNotNull(capture); Assert.AreEqual("000", capture.ResponseCode); return(capture); }
protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { string response = await request.Content.ReadAsStringAsync(); // gather information var json = JsonDoc.Parse(response, JsonEncoders.Base64Encoder); var timestamp = json.GetValue <string>("TIMESTAMP"); var merchantId = json.GetValue <string>("MERCHANT_ID"); var account = json.GetValue <string>("ACCOUNT"); var orderId = json.GetValue <string>("ORDER_ID"); var amount = json.GetValue <string>("AMOUNT"); var currency = json.GetValue <string>("CURRENCY"); var autoSettle = json.GetValue <int>("AUTO_SETTLE_FLAG") == 1; var requestHash = json.GetValue <string>("SHA1HASH"); // check hash var newhash = GenerationUtils.GenerateHash(_sharedSecret, timestamp, merchantId, orderId, amount, currency); if (!newhash.Equals(requestHash)) { return(BadRequest("Incorrect hash. Please check your code and the Developers Documentation.")); } // configure the container ServicesContainer.ConfigureService(new GatewayConfig { MerchantId = merchantId, AccountId = account, ServiceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi", SharedSecret = _sharedSecret }, "realexResponder"); // gather additional information var shippingCode = json.GetValue <string>("SHIPPING_CODE"); var shippingCountry = json.GetValue <string>("SHIPPING_CO"); var billingCode = json.GetValue <string>("BILLING_CODE"); var billingCountry = json.GetValue <string>("BILLING_CO"); // build request AuthorizationBuilder gatewayRequest = null; if (amount == null) { var validate = json.GetValue <int>("VALIDATE_CARD_ONLY") == 1; if (validate) { gatewayRequest = _card.Verify(); } else { gatewayRequest = _card.Verify().WithRequestMultiUseToken(true); } } else { if (autoSettle) { gatewayRequest = _card.Charge(amount.ToAmount()); } else { gatewayRequest = _card.Authorize(amount.ToAmount()); } } try { gatewayRequest.WithCurrency(currency).WithOrderId(orderId).WithTimestamp(timestamp); if (billingCode != null || billingCountry != null) { gatewayRequest.WithAddress(new Address { PostalCode = billingCode, Country = billingCountry }); } if (shippingCode != null || shippingCountry != null) { gatewayRequest.WithAddress(new Address { PostalCode = shippingCode, Country = shippingCountry }, AddressType.Shipping); } var gatewayResponse = gatewayRequest.Execute("realexResponder"); if (gatewayResponse.ResponseCode.Equals("00")) { return(BuildResponse(HttpStatusCode.OK, ConvertResponse(json, gatewayResponse))); } else { return(BadRequest(gatewayResponse.ResponseMessage)); } } catch (ApiException exc) { return(ServerError(exc.Message)); } }
protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { string response = await request.Content.ReadAsStringAsync(); // gather information var json = JsonDoc.Parse(response, JsonEncoders.Base64Encoder); var timestamp = json.GetValue <string>("TIMESTAMP"); var merchantId = json.GetValue <string>("MERCHANT_ID"); var account = json.GetValue <string>("ACCOUNT"); var orderId = json.GetValue <string>("ORDER_ID"); var amount = json.GetValue <string>("AMOUNT"); var currency = json.GetValue <string>("CURRENCY"); var autoSettle = json.GetValue <int>("AUTO_SETTLE_FLAG") == 1; var description = json.GetValue <string>("COMMENT1"); var shaHashTagName = _shaHashType + "HASH"; var requestHash = json.GetValue <string>(shaHashTagName); // gather additional information var shippingCode = json.GetValue <string>("SHIPPING_CODE"); var shippingCountry = json.GetValue <string>("SHIPPING_CO"); var billingCode = json.GetValue <string>("BILLING_CODE"); var billingCountry = json.GetValue <string>("BILLING_CO"); var fraudFilterMode = json.GetValue <string>("HPP_FRAUDFILTER_MODE"); List <string> hashParam = new List <string> { timestamp, merchantId, orderId, amount, currency }; //create the card/APM/LPM/OB object if (json.Has("PM_METHODS")) { string[] apmTypes = json.GetValue <string>("PM_METHODS").Split("|"); string apmType = apmTypes[0]; //OB if (apmTypes.Contains(HostedPaymentMethods.OB.ToString())) { var card = new BankPayment { SortCode = json.GetValue <string>("HPP_OB_DST_ACCOUNT_SORT_CODE"), AccountNumber = json.GetValue <string>("HPP_OB_DST_ACCOUNT_NUMBER"), AccountName = json.GetValue <string>("HPP_OB_DST_ACCOUNT_NAME"), BankPaymentType = (BankPaymentType)(Enum.Parse(typeof(BankPaymentType), json.GetValue <string>("HPP_OB_PAYMENT_SCHEME"))), Iban = json.GetValue <string>("HPP_OB_DST_ACCOUNT_IBAN"), ReturnUrl = json.GetValue <string>("MERCHANT_RESPONSE_URL"), StatusUpdateUrl = json.GetValue <string>("HPP_TX_STATUS_URL") }; paymentMethod = card; if (!string.IsNullOrEmpty(card.SortCode)) { hashParam.Add(card.SortCode); } if (!string.IsNullOrEmpty(card.AccountNumber)) { hashParam.Add(card.AccountNumber); } if (!string.IsNullOrEmpty(card.Iban)) { hashParam.Add(card.Iban); } } else { AlternativePaymentMethod apm = new AlternativePaymentMethod(); apm.AlternativePaymentMethodType = (AlternativePaymentType)(Enum.Parse(typeof(AlternativePaymentType), apmType)); apm.ReturnUrl = json.GetValue <string>("MERCHANT_RESPONSE_URL"); apm.StatusUpdateUrl = json.GetValue <string>("HPP_TX_STATUS_URL"); if (apmType.Equals(AlternativePaymentType.PAYPAL.ToString())) { apm.CancelUrl = "https://www.example.com/failure/cancelURL"; } apm.Country = json.GetValue <string>("HPP_CUSTOMER_COUNTRY"); apm.AccountHolderName = json.GetValue <string>("HPP_CUSTOMER_FIRSTNAME") + " " + json.GetValue <string>("HPP_CUSTOMER_LASTNAME"); paymentMethod = apm; } } else { CreditCardData card = new CreditCardData { Number = "4111111111111111", ExpMonth = 12, ExpYear = 2025, Cvn = "123", CardHolderName = "John Smithe" }; paymentMethod = card; } //for stored card if (json.Has("OFFER_SAVE_CARD")) { if (json.Has("PAYER_REF")) { hashParam.Add(json.GetValue <string>("PAYER_REF")); } if (json.Has("PMT_REF")) { hashParam.Add(json.GetValue <string>("PMT_REF")); } } if (json.Has("HPP_FRAUDFILTER_MODE")) { hashParam.Add(json.GetValue <string>("HPP_FRAUDFILTER_MODE")); } // check hash var newhash = GenerationUtils.GenerateHash(_sharedSecret, hashParam.ToArray()); if (!newhash.Equals(requestHash)) { return(BadRequest("Incorrect hash. Please check your code and the Developers Documentation.")); } // configure the container ServicesContainer.ConfigureService(new GpEcomConfig { MerchantId = merchantId, AccountId = account, SharedSecret = _sharedSecret, RequestLogger = new RequestConsoleLogger() }, "realexResponder"); // build request AuthorizationBuilder gatewayRequest = null; if (amount.ToAmount().Equals(0m) || amount == null) { var validate = json.GetValue <int>("VALIDATE_CARD_ONLY") == 1; if (validate) { gatewayRequest = ((CreditCardData)paymentMethod).Verify(); } else { gatewayRequest = ((CreditCardData)paymentMethod).Verify().WithRequestMultiUseToken(true); } } else { if (autoSettle) { if (paymentMethod is CreditCardData) { gatewayRequest = ((CreditCardData)paymentMethod).Charge(amount.ToAmount()); } if (paymentMethod is AlternativePaymentMethod) { gatewayRequest = ((AlternativePaymentMethod)paymentMethod).Charge(amount.ToAmount()); } if (paymentMethod is BankPayment) { var gatewayBankRequest = AddRemittanceRef(((BankPayment)paymentMethod).Charge(amount.ToAmount()) .WithCurrency(currency) .WithDescription(description), json); var gatewayResponse = gatewayBankRequest.Execute(); if (gatewayResponse.BankPaymentResponse.PaymentStatus.Equals("PAYMENT_INITIATED")) { return(BuildResponse(HttpStatusCode.OK, ConvertResponse(json, gatewayResponse))); } else { return(BadRequest(gatewayResponse.ResponseMessage)); } } } else { gatewayRequest = ((CreditCardData)paymentMethod).Authorize(amount.ToAmount()); } } try { gatewayRequest.WithCurrency(currency).WithOrderId(orderId).WithTimestamp(timestamp); if (billingCode != null || billingCountry != null) { gatewayRequest.WithAddress(new Address { PostalCode = billingCode, Country = billingCountry }); } if (shippingCode != null || shippingCountry != null) { gatewayRequest.WithAddress(new Address { PostalCode = shippingCode, Country = shippingCountry }, AddressType.Shipping); } if (fraudFilterMode != null) { gatewayRequest.WithFraudFilter((FraudFilterMode)Enum.Parse(typeof(FraudFilterMode), fraudFilterMode), getFraudFilterRules(json)); } var gatewayResponse = gatewayRequest.Execute("realexResponder"); if (gatewayResponse.ResponseCode.Equals("00") || gatewayResponse.ResponseCode.Equals("01")) { return(BuildResponse(HttpStatusCode.OK, ConvertResponse(json, gatewayResponse))); } else { return(BadRequest(gatewayResponse.ResponseMessage)); } } catch (ApiException exc) { return(ServerError(exc.Message)); } }