boolean validateExpiryDate(Calendar now) { if (!validateExpMonth()) { return false; } if (!validateExpYear(now)) { return false; } return !ModelUtils.hasMonthPassed(expYear, expMonth, now); }
private ShippingInformation getExampleShippingInfo() { Address address = new Address.Builder() .setCity("San Francisco") .setCountry("US") .setLine1("123 Market St") .setLine2("#345") .setPostalCode("94107") .setState("CA") .build(); return new ShippingInformation(address, "Fake Name", "(555) 555-5555"); } }
/** * Create a custom {@link PaymentIntentParams}. Incorrect attributes may result in errors * when connecting to Stripe's API. * * @return an empty Params object. Call the setter methods on this class to specific values on * the params */ public static PaymentIntentParams createCustomParams() { return new PaymentIntentParams(); }
@Nullable public String getTokenizationMethod() { Source paymentAsSource = asSource(); Card paymentAsCard = asCard(); if (paymentAsSource != null && paymentAsSource.getType().equals(Source.CARD)) { SourceCardData cardData = (SourceCardData) paymentAsSource.getSourceTypeModel(); if (cardData != null) { return cardData.getTokenizationMethod(); } } else if (paymentAsCard != null) { return paymentAsCard.getTokenizationMethod(); } return null; }
@Override public void onCustomerRetrieved(@NonNull Customer customer) { String sourceId = customer.getDefaultSource(); if (sourceId == null) { displayError("No payment method selected"); return; } CustomerSource source = customer.getSourceById(sourceId); proceedWithPurchaseIf3DSCheckIsNotNecessary(source.asSource(), customer.getId()); }
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; }
@Test public void createConfirmPaymentIntentWithSourceDataParams_withAllFields_hasExpectedFields() { SourceParams sourceParams = SourceParams.createCardParams(FULL_FIELDS_VISA_CARD); PaymentIntentParams params = PaymentIntentParams.createConfirmPaymentIntentWithSourceDataParams( sourceParams, TEST_CLIENT_SECRET, TEST_RETURN_URL); Assert.assertEquals(TEST_CLIENT_SECRET, params.getClientSecret()); Assert.assertEquals(TEST_RETURN_URL, params.getReturnUrl()); Assert.assertEquals(sourceParams, params.getSourceParams()); }
private void finishWithSelection(String selectedSourceId) { CustomerSource customerSource = mCustomer.getSourceById(selectedSourceId); if (customerSource != null) { Intent intent = new Intent(); intent.putExtra(EXTRA_SELECTED_PAYMENT, customerSource.toString()); setResult(RESULT_OK, intent); } else { setResult(RESULT_CANCELED); } finish(); }
@Nullable public static ShippingInformation fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } ShippingInformation shippingInformation = new ShippingInformation(); shippingInformation.mName = optString(jsonObject, FIELD_NAME); shippingInformation.mPhone = optString(jsonObject, FIELD_PHONE); shippingInformation.mAddress = Address.fromJson(jsonObject.optJSONObject(FIELD_ADDRESS)); return shippingInformation; }
/** * Generate a new {@link Card} object based on the arguments held by this Builder. * * @return the newly created {@link Card} object */ public Card build() { return new Card(this); } }
@Nullable public static SourceRedirect fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } String returnUrl = optString(jsonObject, FIELD_RETURN_URL); @Status String status = asStatus(optString(jsonObject, FIELD_STATUS)); String url = optString(jsonObject, FIELD_URL); return new SourceRedirect(returnUrl, status, url); }
@Override public ShippingInformation createFromParcel(Parcel source) { return new ShippingInformation(source); }
@Nullable public static Address fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } String city = optString(jsonObject, FIELD_CITY); String country = optString(jsonObject, FIELD_COUNTRY); String line1 = optString(jsonObject, FIELD_LINE_1); String line2 = optString(jsonObject, FIELD_LINE_2); String postalCode = optString(jsonObject, FIELD_POSTAL_CODE); String state = optString(jsonObject, FIELD_STATE); return new Address(city, country, line1, line2, postalCode, state); }
/** * Show a dialog with a link to the external verification site. * * @param source the {@link Source} to verify */ void showDialog(final Source source) { // Caching the source object here because this app makes a lot of them. mRedirectSource = source; mRedirectDialogController.showDialog(source.getRedirect().getUrl()); }
@Override public int hashCode() { int result = (int) (mCartTotal ^ (mCartTotal >>> 32)); result = 31 * result + (mIsPaymentReadyToCharge ? 1 : 0); result = 31 * result + mSelectedPaymentMethodId.hashCode(); result = 31 * result + (int) (mShippingTotal ^ (mShippingTotal >>> 32)); result = 31 * result + mPaymentResult.hashCode(); result = 31 * result + (mShippingInformation != null ? mShippingInformation.hashCode() : 0); result = 31 * result + (mShippingMethod != null ? mShippingMethod.hashCode() : 0); return result; }
private SourceSepaDebitData() { super(); addStandardFields( FIELD_BANK_CODE, FIELD_BRANCH_CODE, FIELD_COUNTRY, FIELD_FINGERPRINT, FIELD_LAST4, FIELD_MANDATE_REFERENCE, FIELD_MANDATE_URL); }
/** * Checks whether or not the {@link #expYear} field is valid. * * @return {@code true} if valid, {@code false} otherwise. */ boolean validateExpYear(Calendar now) { return expYear != null && !ModelUtils.hasYearPassed(expYear, now); }
public Address build() { return new Address(this); }
@NonNull private ShippingInformation getExampleShippingInfo() { Address address = new Address.Builder() .setCity("San Francisco") .setCountry("US") .setLine1("123 Market St") .setLine2("#345") .setPostalCode("94107") .setState("CA") .build(); return new ShippingInformation(address, "Fake Name", "(555) 555-5555"); }