private static Map<String,Object> makeCardParams( CreditCard creditCard, boolean update, String cardNumber, byte expirationMonth, short expirationYear, String cardCode ) { Map<String,Object> cardParams = new HashMap<String,Object>(); addParam(update, cardParams, "number", CreditCard.numbersOnly(cardNumber)); addParam(update, cardParams, "exp_month", expirationMonth); addParam(update, cardParams, "exp_year", expirationYear); addParam(update, cardParams, "cvc", cardCode); addCardParams(creditCard, update, cardParams); return cardParams; }
/** 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#update_customer */ private static void addCustomerParams( CreditCard creditCard, boolean update, Map<String,Object> customerParams ) { addParam(update, customerParams, "description", creditCard.getComments()); addParam(update, customerParams, "email", creditCard.getEmail()); addParam(update, customerParams, "metadata", makeMetadata(creditCard, update)); }
/** https://stripe.com/docs/api#update_card */ private static void addCardParams( CreditCard creditCard, boolean update, Map<String,Object> cardParams ) { addParam(update, cardParams, "name", CreditCard.getFullName(creditCard.getFirstName(), creditCard.getLastName())); addParam(update, cardParams, "address_line1", creditCard.getStreetAddress1()); addParam(update, cardParams, "address_line2", creditCard.getStreetAddress2()); addParam(update, cardParams, "address_city", creditCard.getCity()); addParam(update, cardParams, "address_zip", creditCard.getPostalCode()); addParam(update, cardParams, "address_state", creditCard.getState()); addParam(update, cardParams, "address_country", creditCard.getCountryCode()); }
/** 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>
@Override public void updateCreditCardExpiration( CreditCard creditCard, byte expirationMonth, short expirationYear ) throws IOException { // Update the default Card Map<String,Object> updateParams = new HashMap<String,Object>(); addParam(true, updateParams, "exp_month", expirationMonth); addParam(true, updateParams, "exp_year", expirationYear); try { Customer customer = Customer.retrieve(creditCard.getProviderUniqueId(), options); CustomerCardCollection cards = customer.getCards(); Card defaultCard = cards.retrieve(customer.getDefaultCard(), options); defaultCard.update(updateParams, options); } catch(StripeException e) { ConvertedError converted = convertError(e); // TODO: Throw ErrorCodeException to provide more details throw new LocalizedIOException(e, accessor, "MerchantServicesProvider.updateCreditCardExpiration.notSuccessful"); } }
addParam(false, chargeParams, "amount", amount); addParam(false, chargeParams, "currency", currency.getCurrencyCode()); if(creditCard.getProviderUniqueId() != null) { addParam(false, chargeParams, "customer", creditCard.getProviderUniqueId()); } else { addParam(false, chargeParams, "card", makeCardParams(creditCard, false)); 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); addParam(false, chargeParams, "receipt_email", creditCard.getEmail()); addParam(false, chargeParams, "shipping", makeShippingParams(transactionRequest, creditCard, false)); try { Charge charge = Charge.create(chargeParams, options);
@Override public String storeCreditCard(CreditCard creditCard) throws IOException { // Create the Customer Map<String,Object> customerParams = new HashMap<String,Object>(); addParam(false, customerParams, "card", makeCardParams(creditCard, false)); addCustomerParams(creditCard, false, customerParams); // Make API call try { Customer customer = Customer.create(customerParams, options); return customer.getId(); } catch(StripeException e) { ConvertedError converted = convertError(e); // TODO: Throw ErrorCodeException to provide more details throw new LocalizedIOException(e, accessor, "MerchantServicesProvider.storeCreditCard.notSuccessful"); } }
@Override public void updateCreditCardNumberAndExpiration( CreditCard creditCard, String cardNumber, byte expirationMonth, short expirationYear, String cardCode ) throws IOException { // Replace the default Card Map<String,Object> cardParams = makeCardParams( creditCard, true, cardNumber, expirationMonth, expirationYear, cardCode!=null ? CreditCard.numbersOnly(cardCode) : creditCard.getCardCode() ); Map<String,Object> updateParams = new HashMap<String,Object>(); addParam(true, updateParams, "card", cardParams); try { Customer customer = Customer.retrieve(creditCard.getProviderUniqueId(), options); customer.update(updateParams, options); } catch(StripeException e) { ConvertedError converted = convertError(e); // TODO: Throw ErrorCodeException to provide more details throw new LocalizedIOException(e, accessor, "MerchantServicesProvider.updateCreditCardNumberAndExpiration.notSuccessful"); } }