本文整理汇总了Java中com.google.android.gms.wallet.LineItem类的典型用法代码示例。如果您正苦于以下问题:Java LineItem类的具体用法?Java LineItem怎么用?Java LineItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LineItem类属于com.google.android.gms.wallet包,在下文中一共展示了LineItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFullWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
FullWalletRequest getFullWalletRequest() {
return FullWalletRequest.newBuilder()
.setGoogleTransactionId(mMaskedWallet.getGoogleTransactionId())
.setCart(Cart.newBuilder()
.setCurrencyCode(Constants.DEFAULT_CURRENCY.getCode())
.setTotalPrice("2.00")
.addLineItem(LineItem.newBuilder()
.setCurrencyCode(Constants.DEFAULT_CURRENCY.getCode())
.setDescription(mShopItem.getName())
.setQuantity(Integer.toString(mShopItem.getAmount()))
.setUnitPrice("2.00")
.setTotalPrice("2.00")
.build())
.build())
.build();
}
示例2: createFullWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
/**
*
* @param products {@link Product} to use for creating
* the {@link com.google.android.gms.wallet.FullWalletRequest}
* @param googleTransactionId
* @return {@link FullWalletRequest} instance
*/
public static FullWalletRequest createFullWalletRequest(List<Product> products,
String orderTotal,
String googleTransactionId,
Context context) {
List<LineItem> lineItems = buildLineItems(products, false, context);
// [START full_wallet_request]
FullWalletRequest request = FullWalletRequest.newBuilder()
.setGoogleTransactionId(googleTransactionId)
.setCart(Cart.newBuilder()
.setCurrencyCode(PreferencesUtil.getDefaultSharedPreferences(context).getString(context.getString(R.string.active_currency), "USD"))
.setTotalPrice(orderTotal)
.setLineItems(lineItems)
.build())
.build();
// [END full_wallet_request]
return request;
}
示例3: PayCart
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
protected PayCart(Parcel in) {
currencyCode = in.readString();
countryCode = in.readString();
merchantName = in.readString();
shipsToCountries = Collections.unmodifiableList(in.createStringArrayList());
shippingAddressRequired = in.readByte() != 0;
phoneNumberRequired = in.readByte() != 0;
lineItems = Collections.unmodifiableList(in.createTypedArrayList(LineItem.CREATOR));
subtotal = BigDecimal.valueOf(in.readDouble()).setScale(2, RoundingMode.HALF_EVEN);
if (in.readByte() == 1) {
taxPrice = BigDecimal.valueOf(in.readDouble()).setScale(2, RoundingMode.HALF_EVEN);
} else {
taxPrice = null;
}
if (in.readByte() == 1) {
shippingPrice = BigDecimal.valueOf(in.readDouble()).setScale(2, RoundingMode.HALF_EVEN);
} else {
shippingPrice = null;
}
totalPrice = BigDecimal.valueOf(in.readDouble()).setScale(2, RoundingMode.HALF_EVEN);
}
示例4: cartBuilder
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
Cart.Builder cartBuilder() {
Cart.Builder builder = Cart.newBuilder()
.setCurrencyCode(currencyCode)
.setTotalPrice(totalPrice.toString())
.setLineItems(lineItems);
if (taxPrice != null) {
builder.addLineItem(LineItem.newBuilder()
.setCurrencyCode(currencyCode)
.setDescription("Tax")
.setRole(LineItem.Role.TAX)
.setTotalPrice(taxPrice.toString())
.build());
}
if (shippingPrice != null) {
builder.addLineItem(LineItem.newBuilder()
.setCurrencyCode(currencyCode)
.setDescription("Shipping")
.setRole(LineItem.Role.SHIPPING)
.setTotalPrice(shippingPrice.toString())
.build());
}
return builder;
}
示例5: addLineItem
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
public Builder addLineItem(@NonNull final String title, final int quantity, @NonNull final BigDecimal price) {
checkNotEmpty(title, "title can't be empty");
if (quantity <= 0) {
throw new IllegalArgumentException("quantity can't be less than 1");
}
checkNotNull(price, "price == null");
LineItem lineItem = LineItem.newBuilder()
.setQuantity(Integer.toString(quantity))
.setUnitPrice(price.toString())
.setTotalPrice(price.multiply(BigDecimal.valueOf(quantity)).toString())
.setDescription(title)
.setCurrencyCode(currencyCode)
.setRole(Role.REGULAR)
.build();
lineItems.add(lineItem);
lineItemSubtotal = lineItemSubtotal.add(price.multiply(BigDecimal.valueOf(quantity)));
return this;
}
示例6: getFullWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
FullWalletRequest getFullWalletRequest() {
return FullWalletRequest.newBuilder()
.setGoogleTransactionId(mMaskedWallet.getGoogleTransactionId())
.setCart(Cart.newBuilder()
.setCurrencyCode(Constants.CURRENCY_CODE)
.setTotalPrice(Constants.AMOUNT)
.addLineItem(LineItem.newBuilder()
.setCurrencyCode(Constants.CURRENCY_CODE)
.setDescription("Iced Coffee")
.setQuantity("1")
.setUnitPrice(Constants.AMOUNT)
.setTotalPrice(Constants.AMOUNT)
.build())
.build())
.build();
}
示例7: createMaskedWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
/**
* Creates a MaskedWalletRequest
*
* @param itemInfo {@link com.google.android.gms.samples.wallet.ItemInfo} containing details
* of an item.
* @return {@link MaskedWalletRequest} instance
*/
public static MaskedWalletRequest createMaskedWalletRequest(ItemInfo itemInfo) {
// Build a List of all line items
List<LineItem> lineItems = buildLineItems(itemInfo, true);
// Calculate the cart total by iterating over the line items.
String cartTotal = calculateCartTotal(lineItems);
return MaskedWalletRequest.newBuilder()
.setMerchantName(Constants.MERCHANT_NAME)
.setPhoneNumberRequired(true)
.setShippingAddressRequired(true)
.setCurrencyCode(Constants.CURRENCY_CODE_USD)
.setEstimatedTotalPrice(cartTotal)
// Create a Cart with the current line items. Provide all the information
// available up to this point with estimates for shipping and tax included.
.setCart(Cart.newBuilder()
.setCurrencyCode(Constants.CURRENCY_CODE_USD)
.setTotalPrice(cartTotal)
.setLineItems(lineItems)
.build())
// Indicate whether we need the Wallet Objects associated with the user.
.setShouldRetrieveWalletObjects(true)
.build();
}
示例8: calculateCartTotal
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
/**
*
* @param lineItems List of {@link com.google.android.gms.wallet.LineItem} used for calculating
* the cart total.
* @return cart total.
*/
private static String calculateCartTotal(List<LineItem> lineItems) {
BigDecimal cartTotal = BigDecimal.ZERO;
// Calculate the total price by adding up each of the line items
for (LineItem lineItem: lineItems) {
BigDecimal lineItemTotal = lineItem.getTotalPrice() == null ?
new BigDecimal(lineItem.getUnitPrice())
.multiply(new BigDecimal(lineItem.getQuantity())) :
new BigDecimal(lineItem.getTotalPrice());
cartTotal = cartTotal.add(lineItemTotal);
}
return cartTotal.setScale(2, RoundingMode.HALF_EVEN).toString();
}
示例9: createFullWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
/**
*
* @param itemInfo {@link com.google.android.gms.samples.wallet.ItemInfo} to use for creating
* the {@link com.google.android.gms.wallet.FullWalletRequest}
* @param googleTransactionId
* @return {@link FullWalletRequest} instance
*/
public static FullWalletRequest createFullWalletRequest(ItemInfo itemInfo,
String googleTransactionId) {
List<LineItem> lineItems = buildLineItems(itemInfo, false);
String cartTotal = calculateCartTotal(lineItems);
return FullWalletRequest.newBuilder()
.setGoogleTransactionId(googleTransactionId)
.setCart(Cart.newBuilder()
.setCurrencyCode(Constants.CURRENCY_CODE_USD)
.setTotalPrice(cartTotal)
.setLineItems(lineItems)
.build())
.build();
}
示例10: generateMaskedWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
private MaskedWalletRequest generateMaskedWalletRequest() {
MaskedWalletRequest maskedWalletRequest =
MaskedWalletRequest.newBuilder()
.setMerchantName("Google I/O Codelab")
.setPhoneNumberRequired(true)
.setShippingAddressRequired(true)
.setCurrencyCode("USD")
.setShouldRetrieveWalletObjects(true)
.setEstimatedTotalPrice("10.00")
.setCart(Cart.newBuilder()
.setCurrencyCode("USD")
.setTotalPrice("10.00")
.addLineItem(LineItem.newBuilder()
.setCurrencyCode("USD")
.setDescription("Google I/O Sticker")
.setQuantity("1")
.setUnitPrice("10.00")
.setTotalPrice("10.00")
.build())
.build())
.build();
return maskedWalletRequest;
}
示例11: generateFullWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
private FullWalletRequest generateFullWalletRequest(String googleTransactionId) {
FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder()
.setGoogleTransactionId(googleTransactionId)
.setCart(Cart.newBuilder()
.setCurrencyCode("USD")
.setTotalPrice("10.10")
.addLineItem(LineItem.newBuilder()
.setCurrencyCode("USD")
.setDescription("Google I/O Sticker")
.setQuantity("1")
.setUnitPrice("10.00")
.setTotalPrice("10.00")
.build())
.addLineItem(LineItem.newBuilder()
.setCurrencyCode("USD")
.setDescription("Tax")
.setRole(LineItem.Role.TAX)
.setTotalPrice(".10")
.build())
.build())
.build();
return fullWalletRequest;
}
示例12: getMaskedWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
private MaskedWalletRequest getMaskedWalletRequest() {
PaymentMethodTokenizationParameters parameters =
PaymentMethodTokenizationParameters.newBuilder()
.setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN)
.addParameter("publicKey", simplify.getAndroidPayPublicKey())
.build();
Cart cart = Cart.newBuilder()
.setCurrencyCode(Constants.DEFAULT_CURRENCY.getCode())
.setTotalPrice(mShopItem.priceToString())
.addLineItem(LineItem.newBuilder()
.setCurrencyCode(Constants.DEFAULT_CURRENCY.getCode())
.setDescription(mShopItem.getName())
.setQuantity("1")
.setUnitPrice("2.00")
.setTotalPrice("2.00")
.build())
.build();
return MaskedWalletRequest.newBuilder()
.setMerchantName("BookShelf")
.setPhoneNumberRequired(true)
.setShippingAddressRequired(true)
.setCurrencyCode(Constants.DEFAULT_CURRENCY.getCode())
.setCart(cart)
.setEstimatedTotalPrice(Item.priceToString(mShopItem.getTotalPrice()))
.setPaymentMethodTokenizationParameters(parameters)
.build();
}
示例13: createMaskedWalletRequest
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
private static MaskedWalletRequest createMaskedWalletRequest(List<Product> product,
String orderTotal,
PaymentMethodTokenizationParameters parameters,
Context context) {
// Build a List of all line items
List<LineItem> lineItems = buildLineItems(product, true, context);
// [START masked_wallet_request]
MaskedWalletRequest request = MaskedWalletRequest.newBuilder()
.setMerchantName(Constants.MERCHANT_NAME)
.setPhoneNumberRequired(true)
.setShippingAddressRequired(true)
.setCurrencyCode(PreferencesUtil.getDefaultSharedPreferences(context).getString(context.getString(R.string.active_currency), "USD"))
.setEstimatedTotalPrice(orderTotal)
// Create a Cart with the current line items. Provide all the information
// available up to this point with estimates for shipping and tax included.
.setCart(Cart.newBuilder()
.setCurrencyCode(PreferencesUtil.getDefaultSharedPreferences(context).getString(context.getString(R.string.active_currency), "USD"))
.setTotalPrice(orderTotal)
.setLineItems(lineItems)
.build())
.setPaymentMethodTokenizationParameters(parameters)
.build();
return request;
// [END masked_wallet_request]
}
示例14: buildLineItems
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
/**
* Build a list of line items based on the {@link Product} and a boolean that indicates
* whether to use estimated values of tax and shipping for setting up the
* {@link MaskedWalletRequest} or actual values in the case of a {@link FullWalletRequest}
*
* @param products {@link Product} used for building the
* {@link com.google.android.gms.wallet.LineItem} list.
* @param isEstimate {@code boolean} that indicates whether to use estimated values for
* shipping and tax values.
* @return list of line items
*/
private static List<LineItem> buildLineItems(List<Product> products, boolean isEstimate, Context context) {
List<LineItem> list = new ArrayList<LineItem>();
for (Product product : products) {
String itemPrice = toDollars((long) product.getPrice());
list.add(LineItem.newBuilder()
.setCurrencyCode(PreferencesUtil.getDefaultSharedPreferences(context).getString(context.getString(R.string.active_currency), "USD"))
.setDescription(product.getName())
.setQuantity("1")
.setUnitPrice(itemPrice)
.setTotalPrice(itemPrice)
.build());
}
String shippingPrice = toDollars((long) 0.11);
list.add(LineItem.newBuilder()
.setCurrencyCode(PreferencesUtil.getDefaultSharedPreferences(context).getString(context.getString(R.string.active_currency), "USD"))
.setDescription(Constants.DESCRIPTION_LINE_ITEM_SHIPPING)
.setRole(LineItem.Role.SHIPPING)
.setTotalPrice(shippingPrice)
.build());
String tax = toDollars((long) 0.11);
list.add(LineItem.newBuilder()
.setCurrencyCode(PreferencesUtil.getDefaultSharedPreferences(context).getString(context.getString(R.string.active_currency), "USD"))
.setDescription(Constants.DESCRIPTION_LINE_ITEM_TAX)
.setRole(LineItem.Role.TAX)
.setTotalPrice(tax)
.build());
return list;
}
示例15: getAndroidPayCart
import com.google.android.gms.wallet.LineItem; //导入依赖的package包/类
private Cart getAndroidPayCart() {
return Cart.newBuilder()
.setCurrencyCode(Settings.getAndroidPayCurrency(this))
.setTotalPrice("1.00")
.addLineItem(LineItem.newBuilder()
.setCurrencyCode("USD")
.setDescription("Description")
.setQuantity("1")
.setUnitPrice("1.00")
.setTotalPrice("1.00")
.build())
.build();
}