@Test public void testCreate() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final Map<String, Object> params = new HashMap<>(); params.put("source", "btok_123"); // stripe-mock returns a BankAccount instance instead of a Card stubRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources", customer.getId()), params, Card.class, getResourceAsString("/api_fixtures/card.json") ); final Card card = (Card) customer.getSources().create(params); assertNotNull(card); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources", customer.getId()), params ); }
@Test public void testCreate() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final Map<String, Object> params = new HashMap<>(); params.put("source", "btok_123"); // stripe-mock does not always return a Bank Account so we have to mock stubRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources", customer.getId()), params, BankAccount.class, getResourceAsString("/api_fixtures/bank_account.json") ); final BankAccount bankAccount = (BankAccount) customer.getSources().create(params); assertNotNull(bankAccount); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/customers/%s/sources", customer.getId()), params ); }
@Test public void testList() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); Map<String, Object> params = new HashMap<>(); params.put("object", "bank_account"); params.put("limit", 1); // stripe-mock doesn't handle this, so we stub the request final BankAccount stubbedBankAccount = ApiResource.GSON.fromJson( getResourceAsString("/api_fixtures/bank_account.json"), BankAccount.class); final ExternalAccountCollection stubbedCollection = new ExternalAccountCollection(); final List<ExternalAccount> stubbedData = new ArrayList<>(); stubbedData.add(stubbedBankAccount); stubbedCollection.setData(stubbedData); stubRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources", customer.getId()), params, ExternalAccountCollection.class, stubbedCollection.toJson() ); final ExternalAccountCollection externalAccounts = customer.getSources().list(params); assertNotNull(externalAccounts); assertEquals(1, externalAccounts.getData().size()); verifyRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources", customer.getId()) ); final BankAccount bankAccount = (BankAccount) externalAccounts.getData().get(0); assertNotNull(bankAccount); }
@Test public void testList() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final Map<String, Object> params = new HashMap<>(); params.put("object", "card"); params.put("limit", 1); // stripe-mock doesn't handle this, so we stub the request final Card stubbedCard = getCardFixture(customer); final ExternalAccountCollection stubbedCollection = new ExternalAccountCollection(); final List<ExternalAccount> stubbedData = new ArrayList<>(); stubbedData.add(stubbedCard); stubbedCollection.setData(stubbedData); stubRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources", customer.getId()), params, ExternalAccountCollection.class, stubbedCollection.toJson() ); final ExternalAccountCollection externalAccounts = customer.getSources().list(params); assertNotNull(externalAccounts); assertEquals(1, externalAccounts.getData().size()); verifyRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources", customer.getId()) ); final Card card = (Card) externalAccounts.getData().get(0); assertNotNull(card); }
@Test public void testRetrieve() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); // stripe-mock returns a BankAccount instance instead of a Card stubRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources/%s", customer.getId(), CARD_ID), null, Card.class, getResourceAsString("/api_fixtures/card.json") ); final Card card = (Card) customer.getSources().retrieve(CARD_ID); assertNotNull(card); verifyRequest( ApiResource.RequestMethod.GET, String.format("/v1/customers/%s/sources/%s", customer.getId(), CARD_ID) ); }
@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) ); }