public void APMRefundPendingTransaction() { var PaymentMethod = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.TESTPAY, ReturnUrl = "https://www.example.com/returnUrl", StatusUpdateUrl = "https://www.example.com/statusUrl", Descriptor = "Test Transaction", Country = "DE", AccountHolderName = "James Mason" }; try { var response = PaymentMethod.Charge(10m) .WithCurrency("EUR") .WithDescription("New APM") .Execute(); Assert.IsNotNull(response); Assert.AreEqual("01", response.ResponseCode); var refund = response.Refund(10m) .WithCurrency("EUR") .WithAlternativePaymentType(AlternativePaymentType.TESTPAY) .Execute(); } catch (GatewayException ex) { Assert.AreEqual("FAILED", ex.ResponseMessage); } }
public void TestInitialize() { ServicesContainer.ConfigureService(new GpApiConfig { AppId = APP_ID, AppKey = APP_KEY, Channel = Channel.CardNotPresent, RequestLogger = new RequestConsoleLogger() }); paymentMethod = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.PAYPAL, ReturnUrl = "https://7b8e82a17ac00346e91e984f42a2a5fb.m.pipedream.net", StatusUpdateUrl = "https://7b8e82a17ac00346e91e984f42a2a5fb.m.pipedream.net", CancelUrl = "https://7b8e82a17ac00346e91e984f42a2a5fb.m.pipedream.net", Descriptor = "Test Transaction", Country = "GB", AccountHolderName = "James Mason" }; currency = "USD"; // shipping address shippingAddress = new Address { StreetAddress1 = "Apartment 852", StreetAddress2 = "Complex 741", StreetAddress3 = "no", City = "Chicago", PostalCode = "5001", State = "IL", CountryCode = "US" }; }
public void APMForCharge() { var PaymentMethodDetails = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.SOFORT, ReturnUrl = "https://www.example.com/returnUrl", StatusUpdateUrl = "https://www.example.com/statusUrl", Descriptor = "Test Transaction", Country = "DE", AccountHolderName = "James Mason" }; var response = PaymentMethodDetails.Charge(15m) .WithCurrency("EUR") .Execute(); Assert.IsNotNull(response); Assert.AreEqual("01", response.ResponseCode, response.ResponseMessage); }
public void APMPayByBanckApp() { var paymentMethod = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.PAYBYBANKAPP, ReturnUrl = "https://www.example.com/returnUrl", StatusUpdateUrl = "https://www.example.com/statusUrl", Descriptor = "Test Transaction", Country = "GB", AccountHolderName = "James Mason" }; var response = paymentMethod.Charge(10m) .WithCurrency("GBP") .WithDescription("New APM") .Execute(); Assert.IsNotNull(response); Assert.AreEqual("01", response.ResponseCode); }
public void APMPayPal() { var paymentMethod = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.PAYPAL, ReturnUrl = "https://7b8e82a17ac00346e91e984f42a2a5fb.m.pipedream.net", StatusUpdateUrl = "https://7b8e82a17ac00346e91e984f42a2a5fb.m.pipedream.net", CancelUrl = "https://7b8e82a17ac00346e91e984f42a2a5fb.m.pipedream.net", Descriptor = "Test Transaction", Country = "US", AccountHolderName = "James Mason" }; Decimal amount = 10m; string currency = "USD"; var transaction = paymentMethod.Charge(amount) .WithCurrency(currency) .WithDescription("New APM") .Execute(); Assert.IsNotNull(transaction); Assert.AreEqual("00", transaction.ResponseCode); Assert.IsNotNull(transaction.AlternativePaymentResponse.SessionToken); Console.WriteLine("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + transaction.AlternativePaymentResponse.SessionToken); Thread.Sleep(30000); transaction.AlternativePaymentResponse.ProviderReference = "SMKGK7K2BLEUA"; var response = transaction.Confirm(amount) .WithCurrency(currency) .WithAlternativePaymentType(AlternativePaymentType.PAYPAL) .Execute(); Assert.IsNotNull(response); Assert.AreEqual("00", response.ResponseCode); }
public void APMWithoutCurrency() { var PaymentMethod = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.SOFORTUBERWEISUNG, ReturnUrl = "https://www.example.com/returnUrl", StatusUpdateUrl = "https://www.example.com/statusUrl", Descriptor = "Test Transaction", Country = "DE", AccountHolderName = "James Mason" }; try { var response = PaymentMethod.Charge(10m) .WithDescription("New APM") .Execute(); } catch (BuilderException ex) { Assert.AreEqual("Currency cannot be null for this transaction type.", ex.Message); } }
public void TestAlternativePaymentMethodForCharge_withAlternativePaymentMethodResponse() { var PaymentMethodDetails = new AlternativePaymentMethod { AlternativePaymentMethodType = AlternativePaymentType.TESTPAY, ReturnUrl = "https://www.example.com/returnUrl", StatusUpdateUrl = "https://www.example.com/statusUrl", Descriptor = "Test Transaction", Country = "DE", AccountHolderName = "James Mason" }; var response = PaymentMethodDetails.Charge(10m) .WithCurrency("EUR") .WithDescription("New APM") .Execute(); Assert.IsNotNull(response); Assert.IsNotNull(response?.AlternativePaymentResponse.AccountHolderName); Assert.IsNotNull(response?.AlternativePaymentResponse.Country); Assert.IsNotNull(response?.AlternativePaymentResponse.PaymentPurpose); Assert.IsNotNull(response?.AlternativePaymentResponse.RedirectUrl); Assert.AreEqual("01", response.ResponseCode, response.ResponseMessage); }
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)); } }