/** * Meta data contains both card meta data (also associated with "customer" for stored cards) and transaction meta data. * https://stripe.com/docs/api#create_charge */ private static Map<String,Object> makeMetadata(TransactionRequest transactionRequest, CreditCard creditCard, boolean update) { Map<String,Object> metadata = makeMetadata(creditCard, update); // Additional customer meta data addMetaData(update, metadata, "customer_description", creditCard.getComments(), true); addMetaData(update, metadata, "customer_email", creditCard.getEmail(), false); // Transaction meta data addMetaData(update, metadata, "customer_ip", transactionRequest.getCustomerIp(), false); addMetaData(update, metadata, "order_number", transactionRequest.getOrderNumber(), false); addMetaData(update, metadata, "amount", transactionRequest.getAmount(), false); addMetaData(update, metadata, "tax_amount", transactionRequest.getTaxAmount(), false); addMetaData(update, metadata, "tax_exempt", transactionRequest.getTaxExempt(), false); addMetaData(update, metadata, "shipping_amount", transactionRequest.getShippingAmount(), false); addMetaData(update, metadata, "duty_amount", transactionRequest.getDutyAmount(), false); addMetaData(update, metadata, "shipping_company_name", transactionRequest.getShippingCompanyName(), true); addMetaData(update, metadata, "invoice_number", transactionRequest.getInvoiceNumber(), false); addMetaData(update, metadata, "purchase_order_number", transactionRequest.getPurchaseOrderNumber(), false); return metadata; }
/** https://stripe.com/docs/api#create_charge */ private static Map<String,Object> makeShippingAddressParams(TransactionRequest transactionRequest, boolean update) { Map<String,Object> shippingAddressParams = new HashMap<String,Object>(); addParam(update, shippingAddressParams, "line1", transactionRequest.getShippingStreetAddress1()); addParam(update, shippingAddressParams, "line2", transactionRequest.getShippingStreetAddress2()); addParam(update, shippingAddressParams, "city", transactionRequest.getShippingCity()); addParam(update, shippingAddressParams, "state", transactionRequest.getShippingState()); addParam(update, shippingAddressParams, "postal_code", transactionRequest.getShippingPostalCode()); addParam(update, shippingAddressParams, "country", transactionRequest.getShippingCountryCode()); return shippingAddressParams; }
/** https://stripe.com/docs/api#create_charge */ private static Map<String,Object> makeShippingParams(TransactionRequest transactionRequest, CreditCard creditCard, boolean update) { Map<String,Object> shippingParams = new HashMap<String,Object>(); addParam(update, shippingParams, "address", makeShippingAddressParams(transactionRequest, update)); addParam(update, shippingParams, "name", CreditCard.getFullName(transactionRequest.getShippingFirstName(), transactionRequest.getShippingLastName())); // Phone cannot be in the shipping by itself if(!shippingParams.isEmpty()) addParam(update, shippingParams, "phone", creditCard.getPhone()); // Unused: tracking_number return shippingParams; } // </editor-fold>
private static BigDecimal getAmount(TransactionRequest transactionRequest) { BigDecimal amount = transactionRequest.getAmount(); BigDecimal taxAmount = transactionRequest.getTaxAmount(); if(taxAmount!=null) amount = amount.add(taxAmount); BigDecimal shippingAmount = transactionRequest.getShippingAmount(); if(shippingAmount!=null) amount = amount.add(shippingAmount); BigDecimal dutyAmount = transactionRequest.getDutyAmount(); if(dutyAmount!=null) amount = amount.add(dutyAmount); return amount; }
BigDecimal amount = transactionRequest.getAmount(); BigDecimal taxAmount = transactionRequest.getTaxAmount(); if(taxAmount!=null) amount = amount.add(taxAmount); BigDecimal shippingAmount = transactionRequest.getShippingAmount(); if(shippingAmount!=null) amount = amount.add(shippingAmount); BigDecimal dutyAmount = transactionRequest.getDutyAmount(); if(dutyAmount!=null) amount = amount.add(dutyAmount); amount = amount.setScale(2, RoundingMode.UNNECESSARY); String isoCode = transactionRequest.getCurrency().getCurrencyCode(); if(isoCode.equals("USD")) currencyCode = "840"; else { if(transactionRequest.getTaxExempt()) request.put("UMnontaxable", "yes"); BigDecimal subtotal = transactionRequest.getAmount().setScale(2, RoundingMode.UNNECESSARY); request.put("UMsubtotal", subtotal.toString()); String invoiceNumber = transactionRequest.getInvoiceNumber(); String orderNumber = transactionRequest.getOrderNumber(); if(orderNumber!=null && orderNumber.length()>0) { if(invoiceNumber!=null && invoiceNumber.length()>0) { String ponum = transactionRequest.getPurchaseOrderNumber(); if(ponum!=null && ponum.length()>0) request.put("UMponum", ponum); String description = transactionRequest.getDescription(); if(description != null && description.length()>0) request.put("UMdescription", description);
if(!transactionRequest.getCurrency().getCurrencyCode().equals("USD")) { emptyStringIfNull(transactionRequest.getAmount().toString()), emptyStringIfNull(transactionRequest.getShippingAmount()==null ? null : transactionRequest.getShippingAmount().toString()), emptyStringIfNull(transactionRequest.getTaxAmount()==null ? null : transactionRequest.getTaxAmount().toString()), emptyStringIfNull(transactionRequest.getOrderNumber()), emptyStringIfNull(creditCard.getPhone()), emptyStringIfNull(creditCard.getFax()), emptyStringIfNull(CreditCard.getFullName(transactionRequest.getShippingFirstName(), transactionRequest.getShippingLastName())), emptyStringIfNull(getStreetAddress(transactionRequest.getShippingStreetAddress1(), transactionRequest.getShippingStreetAddress2())), emptyStringIfNull(transactionRequest.getShippingCity()), emptyStringIfNull(transactionRequest.getShippingState()), emptyStringIfNull(transactionRequest.getShippingPostalCode()), emptyStringIfNull(transactionRequest.getShippingCountryCode()) ).get_any() : new WsVaultBankcardLocator().getwsVaultBankcardSoap().VAULT_BANKCARD_AUTHONLY( emptyStringIfNull(transactionRequest.getAmount().toString()), emptyStringIfNull(transactionRequest.getShippingAmount()==null ? null : transactionRequest.getShippingAmount().toString()), emptyStringIfNull(transactionRequest.getTaxAmount()==null ? null : transactionRequest.getTaxAmount().toString()), emptyStringIfNull(transactionRequest.getOrderNumber()), emptyStringIfNull(creditCard.getPhone()), emptyStringIfNull(creditCard.getFax()), emptyStringIfNull(CreditCard.getFullName(transactionRequest.getShippingFirstName(), transactionRequest.getShippingLastName())), emptyStringIfNull(getStreetAddress(transactionRequest.getShippingStreetAddress1(), transactionRequest.getShippingStreetAddress2())), emptyStringIfNull(transactionRequest.getShippingCity()), emptyStringIfNull(transactionRequest.getShippingState()), emptyStringIfNull(transactionRequest.getShippingPostalCode()), emptyStringIfNull(transactionRequest.getShippingCountryCode())
private AuthorizationResult saleOrAuthorize(TransactionRequest transactionRequest, CreditCard creditCard, boolean capture) { if(transactionRequest.getTestMode()) { throw new UnsupportedOperationException("Test mode not currently supported"); BigDecimal totalAmount = transactionRequest.getTotalAmount(); Currency currency = transactionRequest.getCurrency(); int currencyDigits = currency.getDefaultFractionDigits(); if(currencyDigits < 0) throw new AssertionError("currencyDigits < 0: " + currencyDigits); addParam(false, chargeParams, "description", transactionRequest.getDescription()); addParam(false, chargeParams, "metadata", makeMetadata(transactionRequest, creditCard, false)); addParam(false, chargeParams, "capture", capture); if(transactionRequest.getOrderNumber() != null) { String combined = STATEMENT_DESCRIPTOR_PREFIX + transactionRequest.getOrderNumber(); if(combined.length() <= MAX_STATEMENT_DESCRIPTOR_LEN) addParam(false, chargeParams, "statement_descriptor", combined); if(transactionRequest.getEmailCustomer()) { addParam(false, chargeParams, "receipt_email", creditCard.getEmail());
if(!transactionRequest.getCurrency().getCurrencyCode().equals("USD")) throw new ErrorCodeException(TransactionResult.ErrorCode.INVALID_CURRENCY_CODE, "TransactionResult.ErrorCode.INVALID_CURRENCY_CODE"); addField(querySB, "x_exp_date", creditCard.getExpirationDateMMYY()); addField(querySB, "x_card_code", creditCard.getCardCode()); if(transactionRequest.getTestMode()) addField(querySB, "x_test_request", "TRUE"); addField(querySB, "x_duplicate_window", transactionRequest.getDuplicateWindow()); addField(querySB, "x_invoice_num", transactionRequest.getInvoiceNumber()); addField(querySB, "x_description", transactionRequest.getDescription()); addField(querySB, "x_fax", creditCard.getFax()); addField(querySB, "x_email", creditCard.getEmail()); addField(querySB, "x_email_customer", transactionRequest.getEmailCustomer() ? "TRUE" : "FALSE"); addField(querySB, "x_merchant_email", transactionRequest.getMerchantEmail()); addField(querySB, "x_cust_id", creditCard.getCustomerId()); addField(querySB, "x_customer_ip", transactionRequest.getCustomerIp()); addField(querySB, "x_ship_to_first_name", transactionRequest.getShippingFirstName()); addField(querySB, "x_ship_to_last_name", transactionRequest.getShippingLastName()); addField(querySB, "x_ship_to_company", transactionRequest.getShippingCompanyName()); addField(querySB, "x_ship_to_address", getStreetAddress(transactionRequest.getShippingStreetAddress1(), transactionRequest.getShippingStreetAddress2())); addField(querySB, "x_ship_to_city", transactionRequest.getShippingCity()); addField(querySB, "x_ship_to_state", transactionRequest.getShippingState()); addField(querySB, "x_ship_to_zip", CreditCard.numbersOnly(transactionRequest.getShippingPostalCode())); addField(querySB, "x_ship_to_country", transactionRequest.getShippingCountryCode()); addField(querySB, "x_tax", transactionRequest.getTaxAmount()); addField(querySB, "x_freight", transactionRequest.getShippingAmount()); addField(querySB, "x_duty", transactionRequest.getDutyAmount()); addField(querySB, "x_tax_exempt", transactionRequest.getTaxExempt() ? "TRUE" : "FALSE");
SDKProperties.setHostAddress(transactionRequest.getTestMode() ? TEST_HOST_ADDRESS : LIVE_HOST_ADDRESS); SDKProperties.setHostPort(HOST_PORT); SDKProperties.setTimeOut(TIMEOUT); ); PayflowConnectionData connectionData = new PayflowConnectionData( transactionRequest.getTestMode() ? TEST_HOST_ADDRESS : LIVE_HOST_ADDRESS, HOST_PORT, TIMEOUT String ponum = transactionRequest.getPurchaseOrderNumber(); if(ponum!=null && ponum.length()>0) invoice.setPoNum(ponum); String invnum = transactionRequest.getInvoiceNumber(); if(invnum!=null && invnum.length()>0) invoice.setInvNum(invnum); String comment1 = transactionRequest.getDescription(); if(comment1 != null && comment1.length()>0) invoice.setComment1("Transaction Description: "+comment1); String comment2 = creditCard.getComments(); if(comment2 != null && comment2.length()>0) invoice.setComment2("Credit Card Comments: "+comment2); String orderNumber = transactionRequest.getOrderNumber(); if(orderNumber!=null && orderNumber.length()>0) invoice.setCustRef(orderNumber); BigDecimal amount = transactionRequest.getAmount(); BigDecimal taxAmount = transactionRequest.getTaxAmount(); if(taxAmount!=null) amount = amount.add(taxAmount); BigDecimal shippingAmount = transactionRequest.getShippingAmount(); if(shippingAmount!=null) amount = amount.add(shippingAmount); BigDecimal dutyAmount = transactionRequest.getDutyAmount(); if(dutyAmount!=null) amount = amount.add(dutyAmount); invoice.setAmt(new Currency(amount.doubleValue(), transactionRequest.getCurrency().getCurrencyCode()));