/**
* @param _request
* @return
*/
private static final PaymentDetailsType buildPaymentDetails(HttpServletRequest _request) {
PaymentDetailsType details = new PaymentDetailsType();
if (_request.getParameter(PARAM_CUSTOM) != null) {
details.setCustom(_request.getParameter(PARAM_CUSTOM));
}
if (_request.getParameter(PARAM_HANDLING_TOTAL) != null) {
BasicAmountType handlingTotal = new BasicAmountType();
handlingTotal.set_value(_request.getParameter(PARAM_HANDLING_TOTAL));
if (_request.getParameter(PARAM_HANDLING_TOTAL_CURRENCY_ID) != null) {
handlingTotal.setCurrencyID(CurrencyCodeType.fromString(_request.getParameter(PARAM_HANDLING_TOTAL_CURRENCY_ID)));
}
else {
handlingTotal.setCurrencyID(CurrencyCodeType.USD);
}
details.setHandlingTotal(handlingTotal);
}
if (_request.getParameter(PARAM_INVOICE_ID) != null) {
details.setInvoiceID(_request.getParameter(PARAM_INVOICE_ID));
}
if (_request.getParameter(PARAM_ITEM_TOTAL) != null) {
BasicAmountType itemTotal = new BasicAmountType();
itemTotal.set_value(_request.getParameter(PARAM_ITEM_TOTAL));
if (_request.getParameter(PARAM_ITEM_TOTAL_CURRENCY_ID) != null) {
itemTotal.setCurrencyID(CurrencyCodeType.fromString(_request.getParameter(PARAM_ITEM_TOTAL_CURRENCY_ID)));
}
else {
itemTotal.setCurrencyID(CurrencyCodeType.USD);
}
details.setItemTotal(itemTotal);
}
if (_request.getParameter(PARAM_NOTIFY_URL) != null) {
details.setNotifyURL(_request.getParameter(PARAM_NOTIFY_URL));
}
if (_request.getParameter(PARAM_ORDER_DESCRIPTION) != null) {
details.setOrderDescription(_request
.getParameter(PARAM_ORDER_DESCRIPTION));
}
if (_request.getParameter(PARAM_ORDER_TOTAL) != null) {
BasicAmountType orderTotal = new BasicAmountType();
orderTotal.set_value(_request.getParameter(PARAM_ORDER_TOTAL));
if (_request.getParameter(PARAM_ORDER_TOTAL_CURRENCY_ID) != null) {
orderTotal.setCurrencyID(CurrencyCodeType.fromString(_request
.getParameter(PARAM_ORDER_TOTAL_CURRENCY_ID)));
}
details.setOrderTotal(orderTotal);
}
// Loop through line items
int lineNum = 0;
if (_request.getParameter(PARAM_ITEM + lineNum + DOT_AMOUNT) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_NAME) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_NUMBER) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_QUANTITY) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_TAX) != null) {
ArrayList<PaymentDetailsItemType> items = new ArrayList<PaymentDetailsItemType>();
while (_request.getParameter(PARAM_ITEM + lineNum + DOT_AMOUNT) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_NAME) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_NUMBER) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_QUANTITY) != null &&
_request.getParameter(PARAM_ITEM + lineNum + DOT_TAX) != null) {
PaymentDetailsItemType item = new PaymentDetailsItemType();
BasicAmountType amount = new BasicAmountType();
amount.set_value(_request.getParameter(PARAM_ITEM + lineNum + DOT_AMOUNT));
if (_request.getParameter(PARAM_ITEM + lineNum + DOT_AMOUNT_CURRENCY_ID) != null) {
amount.setCurrencyID(CurrencyCodeType.fromString(_request.getParameter(PARAM_ITEM + lineNum + DOT_AMOUNT_CURRENCY_ID)));
}
else {
amount.setCurrencyID(CurrencyCodeType.USD);
}
item.setAmount(amount);
item.setName(_request.getParameter(PARAM_ITEM + lineNum + DOT_NAME));
item.setNumber(_request.getParameter(PARAM_ITEM + lineNum + DOT_NUMBER));
item.setQuantity(new BigInteger(_request.getParameter(PARAM_ITEM + lineNum + DOT_QUANTITY)));
BasicAmountType tax = new BasicAmountType();
tax.set_value(_request.getParameter(PARAM_ITEM + lineNum + DOT_TAX));
if (_request.getParameter(PARAM_ITEM + lineNum + DOT_TAX_CURRENCY_ID) != null) {
tax.setCurrencyID(CurrencyCodeType.fromString(_request.getParameter(PARAM_ITEM + lineNum + DOT_TAX_CURRENCY_ID)));
}
else {
tax.setCurrencyID(CurrencyCodeType.USD);
}
item.setTax(tax);
items.add(item);
lineNum++;
}
details.setPaymentDetailsItem((PaymentDetailsItemType[]) items.toArray(new PaymentDetailsItemType[items.size()]));
}
if (_request.getParameter(PARAM_SHIPPING_TOTAL) != null) {
BasicAmountType shippingTotal = new BasicAmountType();
shippingTotal.set_value(_request.getParameter(PARAM_SHIPPING_TOTAL));
if (_request.getParameter(PARAM_SHIPPING_TOTAL_CURRENCY_ID) != null) {
shippingTotal.setCurrencyID(CurrencyCodeType.fromString(_request
.getParameter(PARAM_SHIPPING_TOTAL_CURRENCY_ID)));
}
else {
shippingTotal.setCurrencyID(CurrencyCodeType.USD);
}
details.setShippingTotal(shippingTotal);
}
if (_request.getParameter(PARAM_ADDRESS_CITY_NAME) != null &&
_request.getParameter(PARAM_ADDRESS_COUNTRY) != null &&
_request.getParameter(PARAM_ADDRESS_NAME) != null &&
_request.getParameter(PARAM_ADDRESS_PHONE) != null &&
_request.getParameter(PARAM_ADDRESS_POSTAL_CODE) != null &&
_request.getParameter(PARAM_ADDRESS_STATE_OR_PROVINCE) != null &&
_request.getParameter(PARAM_ADDRESS_STREET1) != null) {
details.setShipToAddress(buildAddress(_request));
}
if (_request.getParameter(PARAM_TAX_TOTAL) != null) {
BasicAmountType taxTotal = new BasicAmountType();
taxTotal.set_value(_request.getParameter(PARAM_TAX_TOTAL));
if (_request.getParameter(PARAM_TAX_TOTAL_CURRENCY_ID) != null) {
taxTotal.setCurrencyID(CurrencyCodeType.fromString(_request
.getParameter(PARAM_TAX_TOTAL_CURRENCY_ID)));
}
else {
taxTotal.setCurrencyID(CurrencyCodeType.USD);
}
details.setTaxTotal(taxTotal);
}
return details;
}