customer = Customer.retrieve(userStripeId, requestOptions); if (customer.getDeleted() == Boolean.TRUE) { customer = Customer.create(customerParams, requestOptions); userStripeId = customer.getId(); service.setStripeId(webUser.get().id, userStripeId); } else { customer.update(customerParams, requestOptions); customer = Customer.create(customerParams, requestOptions); userStripeId = customer.getId(); service.setStripeId(webUser.get().id, userStripeId); subsParams.put("coupon", coupon); customer.createSubscription(subsParams, requestOptions); return Customer.retrieve(userStripeId, requestOptions).getSubscriptions().getData().stream().map(subs -> new UserSubscription( subs.getPlan().getId(),
@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"); } } }
/** * Delete a customer discount. */ public void deleteDiscount() throws StripeException { deleteDiscount((RequestOptions) null); }
Customer customer = Customer.retrieve(userStripeId, requestOptions); if (customer.getSubscriptions() == null) { return ImmutableList.of(); return customer.getSubscriptions().getData().stream().map(subs -> new UserSubscription( subs.getPlan().getId(),
@Test public void testRetrieve() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); // stripe-mock does not always return a Bank Account so we have to mock stubRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources/%s", customer.getId(), BANK_ACCOUNT_ID), null, BankAccount.class, getResourceAsString("/api_fixtures/bank_account.json") ); final BankAccount bankAccount = (BankAccount) customer.getSources().retrieve(BANK_ACCOUNT_ID); assertNotNull(bankAccount); verifyRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources/%s", customer.getId(), BANK_ACCOUNT_ID) ); }
@Test public void testUpdate() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final Card card = getCardFixture(customer); final Map<String, Object> metadata = new HashMap<>(); metadata.put("key", "value"); final Map<String, Object> params = new HashMap<>(); params.put("metadata", metadata); final Card updatedCard = card.update(params); assertNotNull(updatedCard); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources/%s", customer.getId(), card.getId()), params ); }
public void setCustomerObject(Customer c) { this.customer = new ExpandableField<>(c.getId(), c); } // </editor-fold>
@Test public void testResponseIncluded() throws StripeException { final String idempotencyKey = UUID.randomUUID().toString(); final RequestOptions requestOptions = RequestOptions.builder() .setStripeVersion(Stripe.apiVersion) .setIdempotencyKey(idempotencyKey) .build(); final Customer customer = Customer.create(null, requestOptions); final Customer retrievedCustomer = Customer.retrieve(customer.getId(), requestOptions); final StripeResponse response = retrievedCustomer.getLastResponse(); assertThat(response, instanceOf(StripeResponse.class)); assertEquals(200, response.code()); assertEquals(idempotencyKey, response.idempotencyKey()); assertTrue(response.requestId().startsWith("req_")); assertTrue(response.body().length() > 0); }
@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 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"); } }
@Test public void testDelete() throws StripeException { final Customer customer = getCustomerFixture(); final Customer deletedCustomer = customer.delete(); assertNotNull(deletedCustomer); assertTrue(deletedCustomer.getDeleted()); verifyRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s", customer.getId()) ); }
@Test public void testUpdate() throws StripeException { final Customer customer = getCustomerFixture(); final Map<String, String> metadata = new HashMap<>(); metadata.put("key", "value"); Map<String, Object> params = new HashMap<>(); params.put("metadata", metadata); final Customer updatedCustomer = customer.update(params); assertNotNull(updatedCustomer); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s", customer.getId()), params ); }
@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"); } }
/** * Retrieve a customer. */ public static Customer retrieve(String id) throws StripeException { return retrieve(id, (RequestOptions) null); }
@Test public void testDeleteDiscount() throws StripeException { final Customer customer = getCustomerFixture(); // stripe-mock does not support /v1/customers/%s/discount endpoint, so we stub the request stubRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s/discount", customer.getId()), null, void.class, null ); customer.deleteDiscount(); verifyRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s/discount", customer.getId()) ); } }
/** * Create a customer. */ public static Customer create(Map<String, Object> params) throws StripeException { return create(params, (RequestOptions) null); }
/** * Update a customer. */ @Override public Customer update(Map<String, Object> params) throws StripeException { return update(params, (RequestOptions) null); }
@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"); } }
/** * Delete a customer. */ public Customer delete() throws StripeException { return delete((RequestOptions) null); }
/** * List all customers. */ public static CustomerCollection list(Map<String, Object> params) throws StripeException { return list(params, null); }