/// <summary> /// Create an access token /// </summary> internal static string CreateToken(AuthService authService) { var tokenRequest = new TokenRequest(); tokenRequest.clientKey = Configuration.ClientKey; var cardRequest = new CardRequest(); cardRequest.cardNumber = TestMastercardNumber; cardRequest.cvc = TestCvv; cardRequest.name = "csharplib client"; cardRequest.expiryMonth = 2; cardRequest.expiryYear = 2018; cardRequest.type = "Card"; tokenRequest.paymentMethod = cardRequest; TokenResponse response = authService.GetToken(tokenRequest); return response.token; }
private void createOrder() { var form = HttpContext.Current.Request.Form; var client = new WorldpayRestClient((string)Session["service_key"]); var orderType = (OrderType)Enum.Parse(typeof(OrderType), form["orderType"]); var cardRequest = new CardRequest(); cardRequest.cardNumber = form["number"]; cardRequest.cvc = form["cvv"]; cardRequest.name = form["name"]; cardRequest.expiryMonth = Convert.ToInt32(form["exp-month"]); cardRequest.expiryYear = Convert.ToInt32(form["exp-year"]); cardRequest.type = form["cardType"]; var billingAddress = new Address() { address1 = form["address1"], address2 = form["address2"], address3 = form["address3"], postalCode = form["postcode"], city = form["city"], state = "", countryCode = Enum.Parse(typeof(CountryCode), form["countryCode"]).ToString() }; var is3DS = form["3ds"] == "on" ? true : false; ThreeDSecureInfo threeDSInfo = null; if (is3DS) { var httpRequest = HttpContext.Current.Request; threeDSInfo = new ThreeDSecureInfo() { shopperIpAddress = httpRequest.UserHostAddress, shopperSessionId = HttpContext.Current.Session.SessionID, shopperUserAgent = httpRequest.UserAgent, shopperAcceptHeader = String.Join(";", httpRequest.AcceptTypes) }; } var request = new OrderRequest() { token = form["token"], orderDescription = form["description"], amount = (int)(Convert.ToDecimal(form["amount"]) * 100), currencyCode = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString(), name = is3DS ? "3D" : form["name"], billingAddress = billingAddress, threeDSecureInfo = is3DS ? threeDSInfo : new ThreeDSecureInfo(), is3DSOrder = is3DS, authorizeOnly = form["authoriseOnly"] == "on", orderType = orderType.ToString(), customerIdentifiers = new Dictionary<string, string> { { "my-customer-ref", "customer-ref" } }, customerOrderCode = "A123" }; try { var response = client.GetOrderService().Create(request); HandleSuccessResponse(response); SuccessPanel.Visible = true; } catch (WorldpayException exc) { ErrorControl.DisplayError(exc.apiError); } catch (Exception exc) { throw new InvalidOperationException("Error sending request with token " + request.token, exc); } }
private void createOrder() { var form = HttpContext.Current.Request.Form; var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]); var orderType = (OrderType)Enum.Parse(typeof(OrderType), form["orderType"]); var cardRequest = new CardRequest(); cardRequest.cardNumber = form["number"]; cardRequest.cvc = form["cvv"]; cardRequest.name = form["name"]; cardRequest.expiryMonth = Convert.ToInt32(form["exp-month"]); cardRequest.expiryYear = Convert.ToInt32(form["exp-year"]); cardRequest.type = form["cardType"]; int? _amount = null; var _currencyCode = ""; Dictionary<string, string> custIdentifiers = new Dictionary<string, string>(); try { custIdentifiers = JsonConvert.DeserializeObject<Dictionary<string, string>>(form["customer-identifiers"]); } catch (Exception exc) { } try { _amount = (int)(Convert.ToDecimal(form["amount"]) * 100); } catch (Exception excAmount) { } try { _currencyCode = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString(); } catch (Exception excCurrency) { } var billingAddress = new Address() { address1 = form["address1"], address2 = form["address2"], address3 = form["address3"], postalCode = form["postcode"], city = form["city"], state = "", countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["countryCode"]) }; var deliveryAddress = new DeliveryAddress() { firstName = form["delivery-firstName"], lastName = form["delivery-lastName"], address1 = form["delivery-address1"], address2 = form["delivery-address2"], address3 = form["delivery-address3"], postalCode = form["delivery-postcode"], city = form["delivery-city"], state = "", countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["delivery-countryCode"]) }; var is3DS = form["3ds"] == "on" ? true : false; ThreeDSecureInfo threeDSInfo = null; if (is3DS) { var httpRequest = HttpContext.Current.Request; threeDSInfo = new ThreeDSecureInfo() { shopperIpAddress = httpRequest.UserHostAddress, shopperSessionId = HttpContext.Current.Session.SessionID, shopperUserAgent = httpRequest.UserAgent, shopperAcceptHeader = String.Join(";", httpRequest.AcceptTypes) }; } var request = new OrderRequest() { token = form["token"], orderDescription = form["description"], amount = _amount, currencyCode = _currencyCode, name = is3DS ? "3D" : form["name"], shopperEmailAddress = form["shopper-email"], statementNarrative = form["statement-narrative"], billingAddress = billingAddress, deliveryAddress = deliveryAddress, threeDSecureInfo = is3DS ? threeDSInfo : new ThreeDSecureInfo(), is3DSOrder = is3DS, authorizeOnly = form["authoriseOnly"] == "on", orderType = orderType, customerIdentifiers = custIdentifiers, customerOrderCode = "A123" }; if (!string.IsNullOrEmpty(form["settlement-currency"])) { request.settlementCurrency = form["settlement-currency"]; } try { var response = client.GetOrderService().Create(request); HandleSuccessResponse(response); SuccessPanel.Visible = true; } catch (WorldpayException exc) { ErrorControl.DisplayError(exc.apiError); } catch (Exception exc) { throw new InvalidOperationException("Error sending request with token " + request.token, exc); } }