/** * @param shippingInformation shippingInformation to populated into the widget input fields. */ public void populateShippingInfo(@Nullable ShippingInformation shippingInformation) { if (shippingInformation == null) { return; } Address address = shippingInformation.getAddress(); if (address != null) { mCityEditText.setText(address.getCity()); if (address.getCountry() != null && !address.getCountry().isEmpty()) { mCountryAutoCompleteTextView.setCountrySelected(address.getCountry()); } mAddressEditText.setText(address.getLine1()); mAddressEditText2.setText(address.getLine2()); mPostalCodeEditText.setText(address.getPostalCode()); mStateEditText.setText(address.getState()); } mNameEditText.setText(shippingInformation.getName()); mPhoneNumberEditText.setText(shippingInformation.getPhone()); }
@NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); JSONObject jsonAddressObject = mAddress == null ? null : mAddress.toJson(); JSONObject jsonVerifiedAddressObject = mVerifiedAddress == null ? null : mVerifiedAddress.toJson(); try { if (jsonAddressObject != null && jsonAddressObject.length() > 0) { jsonObject.put(FIELD_ADDRESS, jsonAddressObject); } putStringIfNotNull(jsonObject, FIELD_EMAIL, mEmail); putStringIfNotNull(jsonObject, FIELD_NAME, mName); putStringIfNotNull(jsonObject, FIELD_PHONE, mPhone); if (jsonVerifiedAddressObject != null && jsonVerifiedAddressObject.length() > 0) { jsonObject.put(FIELD_VERIFIED_ADDRESS, jsonVerifiedAddressObject); } putStringIfNotNull(jsonObject, FIELD_VERIFIED_EMAIL, mVerifiedEmail); putStringIfNotNull(jsonObject, FIELD_VERIFIED_NAME, mVerifiedName); putStringIfNotNull(jsonObject, FIELD_VERIFIED_PHONE, mVerifiedPhone); } catch (JSONException ignored) { } return jsonObject; }
@NonNull @Override public Map<String, Object> toMap() { Map<String, Object> hashMap = new HashMap<>(); if (mAddress != null) { hashMap.put(FIELD_ADDRESS, mAddress.toMap()); } hashMap.put(FIELD_EMAIL, mEmail); hashMap.put(FIELD_NAME, mName); hashMap.put(FIELD_PHONE, mPhone); if (mVerifiedAddress != null) { hashMap.put(FIELD_VERIFIED_ADDRESS, mVerifiedAddress.toMap()); } hashMap.put(FIELD_VERIFIED_EMAIL, mVerifiedEmail); hashMap.put(FIELD_VERIFIED_NAME, mVerifiedName); hashMap.put(FIELD_VERIFIED_PHONE, mVerifiedPhone); removeNullAndEmptyParams(hashMap); return hashMap; }
assertTrue(sepaDebitSource.getSourceTypeModel() instanceof SourceSepaDebitData); assertEquals("eur", sepaDebitSource.getCurrency()); assertEquals("Eureka", sepaDebitSource.getOwner().getAddress().getCity()); assertEquals("90210", sepaDebitSource.getOwner().getAddress().getPostalCode()); assertEquals("123 Main St", sepaDebitSource.getOwner().getAddress().getLine1()); assertEquals("EI", sepaDebitSource.getOwner().getAddress().getCountry()); assertEquals("Sepa Account Holder", sepaDebitSource.getOwner().getName()); JsonTestUtils.assertMapEquals(metamap ,sepaDebitSource.getMetaData());
assertTrue(sepaDebitSource.getSourceTypeModel() instanceof SourceSepaDebitData); assertEquals("eur", sepaDebitSource.getCurrency()); assertEquals("Eureka", sepaDebitSource.getOwner().getAddress().getCity()); assertEquals("90210", sepaDebitSource.getOwner().getAddress().getPostalCode()); assertEquals("EI", sepaDebitSource.getOwner().getAddress().getCountry()); assertEquals("Sepa Account Holder", sepaDebitSource.getOwner().getName()); } catch (StripeException stripeEx) {
@Override public void onReceive(Context context, Intent intent) { ShippingInformation shippingInformation = intent.getParcelableExtra(EXTRA_SHIPPING_INFO_DATA); Intent shippingInfoProcessedIntent = new Intent(EVENT_SHIPPING_INFO_PROCESSED); if (shippingInformation.getAddress() == null || !shippingInformation.getAddress().getCountry().equals(Locale.US.getCountry())) { shippingInfoProcessedIntent.putExtra(EXTRA_IS_SHIPPING_INFO_VALID, false); } else { ArrayList<ShippingMethod> shippingMethods = createSampleShippingMethods(); shippingInfoProcessedIntent.putExtra(EXTRA_IS_SHIPPING_INFO_VALID, true); shippingInfoProcessedIntent.putParcelableArrayListExtra(EXTRA_VALID_SHIPPING_METHODS, shippingMethods); shippingInfoProcessedIntent.putExtra(EXTRA_DEFAULT_SHIPPING_METHOD, shippingMethods.get(1)); } LocalBroadcastManager.getInstance(PaymentSessionActivity.this).sendBroadcast(shippingInfoProcessedIntent); } };
private ArrayList<ShippingMethod> getValidShippingMethods(ShippingInformation shippingInformation) { ArrayList<ShippingMethod> shippingMethods = new ArrayList<>(); shippingMethods.add(new ShippingMethod("UPS Ground", "ups-ground", "Arrives in 3-5 days", 0, "USD")); shippingMethods.add(new ShippingMethod("FedEx", "fedex", "Arrives tomorrow", 599, "USD")); if (shippingInformation.getAddress() != null && shippingInformation.getAddress().getPostalCode().equals("94110")) { shippingMethods.add(new ShippingMethod("1 Hour Courier", "courier", "Arrives in the next hour", 1099, "USD")); } return shippingMethods; }
assertTrue(sepaDebitSource.getSourceTypeModel() instanceof SourceSepaDebitData); assertEquals("eur", sepaDebitSource.getCurrency()); assertEquals("Eureka", sepaDebitSource.getOwner().getAddress().getCity()); assertEquals("90210", sepaDebitSource.getOwner().getAddress().getPostalCode()); assertEquals("123 Main St", sepaDebitSource.getOwner().getAddress().getLine1()); assertEquals("EI", sepaDebitSource.getOwner().getAddress().getCountry()); assertEquals("Sepa Account Holder", sepaDebitSource.getOwner().getName()); JsonTestUtils.assertMapEquals(metamap ,sepaDebitSource.getMetaData());
@Override public void onReceive(Context context, Intent intent) { ShippingInformation shippingInformation = intent.getParcelableExtra(EXTRA_SHIPPING_INFO_DATA); Intent shippingInfoProcessedIntent = new Intent(EVENT_SHIPPING_INFO_PROCESSED); if (shippingInformation.getAddress() == null || !shippingInformation.getAddress().getCountry().equals(Locale.US.getCountry())) { shippingInfoProcessedIntent.putExtra(EXTRA_IS_SHIPPING_INFO_VALID, false); } else { ArrayList<ShippingMethod> shippingMethods = getValidShippingMethods(shippingInformation); shippingInfoProcessedIntent.putExtra(EXTRA_IS_SHIPPING_INFO_VALID, true); shippingInfoProcessedIntent.putParcelableArrayListExtra(EXTRA_VALID_SHIPPING_METHODS, shippingMethods); shippingInfoProcessedIntent.putExtra(EXTRA_DEFAULT_SHIPPING_METHOD, shippingMethods.get(0)); } LocalBroadcastManager.getInstance(PaymentActivity.this).sendBroadcast(shippingInfoProcessedIntent); } };
assertNotNull(cardSource.getOwner()); assertNotNull(cardSource.getOwner().getAddress()); assertEquals("Sheboygan", cardSource.getOwner().getAddress().getCity()); assertEquals("WI", cardSource.getOwner().getAddress().getState()); assertEquals("53081", cardSource.getOwner().getAddress().getPostalCode()); assertEquals("123 Main St", cardSource.getOwner().getAddress().getLine1()); assertEquals("#456", cardSource.getOwner().getAddress().getLine2()); assertEquals("US", cardSource.getOwner().getAddress().getCountry()); assertEquals("Winnie Hoop", cardSource.getOwner().getName()); JsonTestUtils.assertMapEquals(metamap, cardSource.getMetaData());
@Test public void fromJsonString_toMap_createsExpectedMap() { assertMapEquals(EXAMPLE_MAP_ADDRESS, mAddress.toMap()); }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_ADDRESS); assertJsonEquals(rawConversion, mAddress.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
@Test public void builderConstructor_whenCalled_createsExpectedAddress() { Address address = new Address.Builder() .setCity("San Francisco") .setCountry("US") .setLine1("123 Market St") .setLine2("#345") .setPostalCode("94107") .setState("CA") .build(); assertMapEquals(address.toMap(), mAddress.toMap()); }
@Test public void createTokenSynchronous_withValidAccount_passesIntegrationTest() { try { final Address exampleAddress = new Address .Builder() .setCity("SF") .setCountry("US") .setState("CA").build(); final Map<String, Object> exampleLegalEntity = new HashMap<String, Object>() {{ put("personal_address", exampleAddress.toMap()); put("type", "individual"); put("ssn_last_4", "1234"); put("first_name", "Kathy"); put("last_name", "Sun"); }}; Stripe stripe = new Stripe(mContext, FUNCTIONAL_PUBLISHABLE_KEY); TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); Token token = stripe.createAccountTokenSynchronous( AccountParams.createAccountParams(true, exampleLegalEntity)); assertNotNull(token); assertEquals(Token.TYPE_ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); assertAllLogsAreValid(listener, 2); } catch (StripeException stripeEx) { fail(stripeEx.getMessage()); } }