class Client { final BankAccount account; public void updateTransaction() { account.update(); // update is synchonized. } public double withdrawFunds() { return account.calculateInterestAndWithdraw(); } }
/** * Delete a bank account. */ @Override public BankAccount delete() throws StripeException { return delete(null); }
/** * Update a bank account. */ @Override public BankAccount update(Map<String, Object> params, RequestOptions options) throws StripeException { return request(RequestMethod.POST, this.getInstanceUrl(), params, BankAccount.class, options); } // </editor-fold>
@Test public void testDelete() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final BankAccount bankAccount = getBankAccountFixture(customer); final String deleteBankAccountData = String.format( "{\"id\": \"%s\", \"object\": \"bank_account\", \"deleted\": true}", bankAccount.getId() ); stubRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s/sources/%s", customer.getId(), bankAccount.getId()), null, BankAccount.class, deleteBankAccountData ); final BankAccount deletedBankAccount = bankAccount.delete(); assertNotNull(deletedBankAccount); assertTrue(deletedBankAccount.getDeleted()); verifyRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s/sources/%s", customer.getId(), bankAccount.getId()) ); }
/** * Update a bank account. */ @Override public BankAccount update(Map<String, Object> params) throws StripeException { return update(params, null); }
@Test public void testUpdate() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final BankAccount bankAccount = getBankAccountFixture(customer); final Map<String, Object> metadata = new HashMap<>(); metadata.put("key", "value"); final Map<String, Object> params = new HashMap<>(); params.put("metadata", metadata); // stripe-mock returns a Card instance instead of a BankAccount stubRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources/%s", customer.getId(), bankAccount.getId()), params, BankAccount.class, getResourceAsString("/api_fixtures/bank_account.json") ); final BankAccount updatedBankAccount = bankAccount.update(params); assertNotNull(updatedBankAccount); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources/%s", customer.getId(), bankAccount.getId()), params ); }
@Test public void testVerify() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final BankAccount bankAccount = getBankAccountFixture(customer); final List<Integer> values = new ArrayList<>(); values.add(32); values.add(45); final Map<String, Object> params = new HashMap<>(); params.put("amounts", values); final BankAccount verifiedBankAccount = (BankAccount) bankAccount.verify(params); assertNotNull(verifiedBankAccount); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources/%s/verify", customer.getId(), bankAccount.getId()), params ); } }
private BankAccount getBankAccountFixture(Customer customer) throws IOException, StripeException { // stripe-mock doesn't handle bank accounts very well just yet, so use a local fixture final BankAccount bankAccount = ApiResource.GSON.fromJson( getResourceAsString("/api_fixtures/bank_account.json"), BankAccount.class); bankAccount.setCustomer(customer.getId()); return bankAccount; }
@Test public void testDeserialize() throws Exception { final String data = getFixture("/v1/customers/cus_123/bank_accounts/ba_123"); final BankAccount bankAccount = ApiResource.GSON.fromJson(data, BankAccount.class); assertNotNull(bankAccount); assertNotNull(bankAccount.getId()); } }
@Test public void testDeserializeWithExpandedDeletedBankAccount() throws IOException { final String data = getResourceAsString( "/api_fixtures/payout_with_del_ext_bank_acct_expansion.json" ); final Payout resource = ApiResource.GSON.fromJson(data, Payout.class); final BankAccount bankAccount = (BankAccount) resource.getDestinationObject(); assertNotNull(bankAccount); assertTrue(bankAccount.getDeleted()); } }
/** * Delete a bank account. */ @Override public BankAccount delete(RequestOptions options) throws StripeException { return request(RequestMethod.DELETE, this.getInstanceUrl(), null, BankAccount.class, options); } // </editor-fold>