public void setDefaultCardObject(Card c) { this.defaultCard = new ExpandableField<>(c.getId(), c); } // </editor-fold>
@Override protected String getInstanceUrl() { String result = super.getInstanceUrl(); if (result != null) { return result; } else if (this.getRecipient() != null) { return String.format("%s/%s/cards/%s", classUrl(Recipient.class), this.getRecipient(), this.getId()); } else { return null; } } }
@Test public void testDeserialize() throws Exception { final String data = getFixture("/v1/customers/cus_123/cards/card_123"); final Card resource = ApiResource.GSON.fromJson(data, Card.class); assertNotNull(resource); assertNotNull(resource.getId()); } }
@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 ); }
@Test public void testDelete() throws IOException, StripeException { final Customer customer = Customer.retrieve(CUSTOMER_ID); final Card card = getCardFixture(customer); final String deleteCardData = String.format( "{\"id\": \"%s\", \"object\": \"card\", \"deleted\": true}", card.getId() ); stubRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s/sources/%s", customer.getId(), card.getId()), null, Card.class, deleteCardData ); final Card deletedCard = card.delete(); assertNotNull(deletedCard); assertTrue(deletedCard.getDeleted()); verifyRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/customers/%s/sources/%s", customer.getId(), card.getId()) ); } }