@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 deleteCreditCard(CreditCard creditCard) throws IOException { try { Customer customer = Customer.retrieve(creditCard.getProviderUniqueId(), options); if(customer.getDeleted() == null || !customer.getDeleted()) { DeletedCustomer deletedCustomer = customer.delete(options); } } catch(StripeException e) { ConvertedError converted = convertError(e); // TODO: Throw ErrorCodeException to provide more details throw new LocalizedIOException(e, accessor, "MerchantServicesProvider.deleteCreditCard.notSuccessful"); } } }
@Override public void updateCreditCard(CreditCard creditCard) throws IOException { // Update the Customer Map<String,Object> updateCustomerParams = new HashMap<String,Object>(); addCustomerParams(creditCard, true, updateCustomerParams); // Update the default Card Map<String,Object> updateCardParams = new HashMap<String,Object>(); addCardParams(creditCard, true, updateCardParams); try { Customer customer = Customer.retrieve(creditCard.getProviderUniqueId(), options); customer.update(updateCustomerParams, options); CustomerCardCollection cards = customer.getCards(); Card defaultCard = cards.retrieve(customer.getDefaultCard(), options); defaultCard.update(updateCardParams, options); } catch(StripeException e) { ConvertedError converted = convertError(e); // TODO: Throw ErrorCodeException to provide more details throw new LocalizedIOException(e, accessor, "MerchantServicesProvider.updateCreditCardNumberAndExpiration.notSuccessful"); } }
@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"); } }
@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"); } }
@Override public CaptureResult capture(AuthorizationResult authorizationResult) { String id = authorizationResult.getProviderUniqueId(); try { authorizationResult.getProviderUniqueId(); Charge ch = Charge.retrieve(id, options); ch.capture(options); return new CaptureResult( providerId, TransactionResult.CommunicationResult.SUCCESS, null, null, null, id ); } catch(StripeException e) { ConvertedError converted = convertError(e); return new CaptureResult( providerId, converted.communicationResult, converted.providerErrorCode, converted.errorCode, converted.providerErrorMessage, id ); } }
ConvertedError converted = convertError(e); if(converted.declineReason == null) { return new AuthorizationResult(