当前位置: 首页>>代码示例>>Java>>正文


Java PostalAddress类代码示例

本文整理汇总了Java中com.braintreepayments.api.models.PostalAddress的典型用法代码示例。如果您正苦于以下问题:Java PostalAddress类的具体用法?Java PostalAddress怎么用?Java PostalAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PostalAddress类属于com.braintreepayments.api.models包,在下文中一共展示了PostalAddress类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestOneTimePayment_postParamsIncludeAddressAndAddressOverride

import com.braintreepayments.api.models.PostalAddress; //导入依赖的package包/类
@Test
public void requestOneTimePayment_postParamsIncludeAddressAndAddressOverride() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();

    PostalAddress address = new PostalAddress()
            .streetAddress("123 Fake St.")
            .extendedAddress("Apt. v.0")
            .locality("Oakland")
            .region("CA")
            .postalCode("12345")
            .countryCodeAlpha2("US");
    PayPalRequest request = new PayPalRequest("3.43")
            .shippingAddressRequired(true)
            .shippingAddressOverride(address);

    PayPal.requestOneTimePayment(fragment, request);

    ArgumentCaptor<String> pathCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(pathCaptor.capture(), dataCaptor.capture(),
            any(HttpResponseCallback.class));
    assertTrue(pathCaptor.getValue().contains("/paypal_hermes/create_payment_resource"));

    JSONObject json = new JSONObject(dataCaptor.getValue());
    assertEquals("3.43", json.get("amount"));
    assertEquals("123 Fake St.", json.get("line1"));
    assertEquals("Apt. v.0", json.get("line2"));
    assertEquals("Oakland", json.get("city"));
    assertEquals("CA", json.get("state"));
    assertEquals("12345", json.get("postal_code"));
    assertEquals("US", json.get("country_code"));
    assertEquals(false, json.getJSONObject("experience_profile").get("no_shipping"));
    assertEquals(true, json.getJSONObject("experience_profile").get("address_override"));
}
 
开发者ID:braintree,项目名称:braintree_android,代码行数:35,代码来源:PayPalUnitTest.java

示例2: requestOneTimePayment_postParamsIncludeNoShippingAndAddressAndAddressOverride

import com.braintreepayments.api.models.PostalAddress; //导入依赖的package包/类
@Test
public void requestOneTimePayment_postParamsIncludeNoShippingAndAddressAndAddressOverride() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();

    PostalAddress address = new PostalAddress()
            .streetAddress("123 Fake St.")
            .extendedAddress("Apt. v.0")
            .locality("Oakland")
            .region("CA")
            .postalCode("12345")
            .countryCodeAlpha2("US");
    PayPalRequest request = new PayPalRequest("3.43")
            .shippingAddressRequired(false)
            .shippingAddressOverride(address);

    PayPal.requestOneTimePayment(fragment, request);

    ArgumentCaptor<String> pathCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(pathCaptor.capture(), dataCaptor.capture(),
            any(HttpResponseCallback.class));
    assertTrue(pathCaptor.getValue().contains("/paypal_hermes/create_payment_resource"));

    JSONObject json = new JSONObject(dataCaptor.getValue());
    assertEquals("3.43", json.get("amount"));
    assertEquals("123 Fake St.", json.get("line1"));
    assertEquals("Apt. v.0", json.get("line2"));
    assertEquals("Oakland", json.get("city"));
    assertEquals("CA", json.get("state"));
    assertEquals("12345", json.get("postal_code"));
    assertEquals("US", json.get("country_code"));
    assertEquals(true, json.getJSONObject("experience_profile").get("no_shipping"));
    assertEquals(true, json.getJSONObject("experience_profile").get("address_override"));
}
 
开发者ID:braintree,项目名称:braintree_android,代码行数:35,代码来源:PayPalUnitTest.java

示例3: formatAddress

import com.braintreepayments.api.models.PostalAddress; //导入依赖的package包/类
private static String formatAddress(PostalAddress address) {
    return address.getRecipientName() + " " +
            address.getStreetAddress() + " " +
            address.getExtendedAddress() + " " +
            address.getLocality() + " " +
            address.getRegion() + " " +
            address.getPostalCode() + " " +
            address.getCountryCodeAlpha2();
}
 
开发者ID:braintree,项目名称:braintree_android,代码行数:10,代码来源:PayPalActivity.java

示例4: formatAddress

import com.braintreepayments.api.models.PostalAddress; //导入依赖的package包/类
private String formatAddress(PostalAddress address) {
    return address.getRecipientName() + " " + address.getStreetAddress() + " " +
        address.getExtendedAddress() + " " + address.getLocality() + " " + address.getRegion() +
            " " + address.getPostalCode() + " " + address.getCountryCodeAlpha2();
}
 
开发者ID:braintree,项目名称:braintree-android-drop-in,代码行数:6,代码来源:MainActivity.java

示例5: createPaymentResource

import com.braintreepayments.api.models.PostalAddress; //导入依赖的package包/类
/**
 * Create a PayPalPaymentResource on behalf of the merchant. To be used in the PayPal Checkout
 * flows for Single Payment and Billing Agreement.
 *
 * @param fragment A {@link BraintreeFragment} used to process the request.
 * @param request A {@link PayPalRequest} used to customize the request.
 * @param isBillingAgreement A boolean. If true, this will use the Billing Agreement. Otherwise,
 *        PayPal will perform a Single Payment.
 * @param callback A callback on the http request.
 */
private static void createPaymentResource(BraintreeFragment fragment, PayPalRequest request,
        boolean isBillingAgreement, HttpResponseCallback callback)
        throws JSONException, ErrorWithResponse, BraintreeException {
    String currencyCode = request.getCurrencyCode();
    if (currencyCode == null) {
        currencyCode = fragment.getConfiguration().getPayPal().getCurrencyIsoCode();
    }

    CheckoutRequest checkoutRequest = getCheckoutRequest(fragment, null);
    JSONObject parameters = new JSONObject()
            .put(RETURN_URL_KEY, checkoutRequest.getSuccessUrl())
            .put(CANCEL_URL_KEY, checkoutRequest.getCancelUrl())
            .put(OFFER_CREDIT_KEY, request.shouldOfferCredit());

    if (fragment.getAuthorization() instanceof ClientToken) {
        parameters.put(AUTHORIZATION_FINGERPRINT_KEY, fragment.getAuthorization().getBearer());
    } else {
        parameters.put(TOKENIZATION_KEY, fragment.getAuthorization().getBearer());
    }

    if (!isBillingAgreement) {
        parameters.put(AMOUNT_KEY, request.getAmount())
                .put(CURRENCY_ISO_CODE_KEY, currencyCode)
                .put(INTENT_KEY, request.getIntent());
    } else {
        if (!TextUtils.isEmpty(request.getBillingAgreementDescription())) {
            parameters.put(DESCRIPTION_KEY, request.getBillingAgreementDescription());
        }
    }

    JSONObject experienceProfile = new JSONObject();
    experienceProfile.put(NO_SHIPPING_KEY, !request.isShippingAddressRequired());
    experienceProfile.put(LANDING_PAGE_TYPE_KEY, request.getLandingPageType());
    String displayName = request.getDisplayName();
    if (TextUtils.isEmpty(displayName)) {
        displayName = fragment.getConfiguration().getPayPal().getDisplayName();
    }
    experienceProfile.put(DISPLAY_NAME_KEY, displayName);

    if (request.getLocaleCode() != null) {
        experienceProfile.put(LOCALE_CODE_KEY, request.getLocaleCode());
    }

    if (request.getShippingAddressOverride() != null) {
        experienceProfile.put(ADDRESS_OVERRIDE_KEY, true);
        PostalAddress shippingAddress = request.getShippingAddressOverride();
        parameters.put(PostalAddress.LINE_1_KEY, shippingAddress.getStreetAddress());
        parameters.put(PostalAddress.LINE_2_KEY, shippingAddress.getExtendedAddress());
        parameters.put(PostalAddress.LOCALITY_KEY, shippingAddress.getLocality());
        parameters.put(PostalAddress.REGION_KEY, shippingAddress.getRegion());
        parameters.put(PostalAddress.POSTAL_CODE_UNDERSCORE_KEY, shippingAddress.getPostalCode());
        parameters.put(PostalAddress.COUNTRY_CODE_UNDERSCORE_KEY, shippingAddress.getCountryCodeAlpha2());
        parameters.put(PostalAddress.RECIPIENT_NAME_UNDERSCORE_KEY, shippingAddress.getRecipientName());
    } else {
        experienceProfile.put(ADDRESS_OVERRIDE_KEY, false);
    }

    parameters.put(EXPERIENCE_PROFILE_KEY, experienceProfile);

    String apiUrl = isBillingAgreement ? SETUP_BILLING_AGREEMENT_ENDPOINT : CREATE_SINGLE_PAYMENT_ENDPOINT;
    String versionedPath = "/v1/" + apiUrl;
    fragment.getHttpClient().post(versionedPath, parameters.toString(), callback);
}
 
开发者ID:braintree,项目名称:braintree_android,代码行数:74,代码来源:PayPal.java


注:本文中的com.braintreepayments.api.models.PostalAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。