@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 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 ); } }
@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()) ); }
@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 ); }