}
public void capturePayment(InvoiceHeader invoiceHeader)
throws PaymentException, Exception {
OrderHeader orderHeader = invoiceHeader.getOrderHeader();
CallerServices caller = new CallerServices();
caller.setAPIProfile(createProfile());
String currencyCode = orderHeader.getSiteCurrency().getSiteCurrencyClass().getCurrency().getCurrencyCode();
OrderEngine orderEngine = new OrderEngine(orderHeader, null);
DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType();
DoExpressCheckoutPaymentRequestDetailsType detail = new DoExpressCheckoutPaymentRequestDetailsType();
detail.setPayerID(payerId);
detail.setToken(token);
detail.setPaymentAction(PaymentActionCodeType.fromString("Sale"));
PaymentDetailsType paymentDetail = new PaymentDetailsType();
BasicAmountType orderTotal = new BasicAmountType();
orderTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
orderTotal.set_value(Format.getSimpleFloat(orderHeader.getOrderTotal()));
paymentDetail.setOrderTotal(orderTotal);
BasicAmountType priceTotal = new BasicAmountType();
priceTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
priceTotal.set_value(Format.getSimpleFloat(orderEngine.getOrderPriceTotal() - orderEngine.getOrderPriceDiscountTotal()));
paymentDetail.setItemTotal(priceTotal);
BasicAmountType taxTotal = new BasicAmountType();
taxTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
taxTotal.set_value(Format.getSimpleFloat(orderEngine.getOrderTaxTotal()));
paymentDetail.setTaxTotal(taxTotal);
float total = orderHeader.getShippingTotal() - orderHeader.getShippingDiscountTotal();
BasicAmountType shippingTotal = new BasicAmountType();
shippingTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
shippingTotal.set_value(Format.getSimpleFloat(total));
paymentDetail.setShippingTotal(shippingTotal);
/*
Vector<PaymentDetailsItemType> paymentItems = new Vector<PaymentDetailsItemType>();
Iterator<?> iterator = orderHeader.getOrderItemDetails().iterator();
while (iterator.hasNext()) {
OrderItemDetail orderItemDetail = (OrderItemDetail) iterator.next();
PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();
Item item = orderItemDetail.getItem();
String itemDesc = orderItemDetail.getItemOrderQty() + " x " + item.getItemShortDesc();
if (item.getItemShortDesc1().length() > 0) {
itemDesc += ", " + item.getItemShortDesc1();
}
paymentItem.setName(itemDesc);
paymentItem.setNumber(item.getItemNum());
paymentItem.setQuantity(BigInteger.valueOf((long) 1));
BasicAmountType itemPriceTotal = new BasicAmountType();
itemPriceTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
itemPriceTotal.set_value(Format.getFloatObj(orderItemDetail.getItemDetailAmount() - orderItemDetail.getItemDetailDiscountAmount()));
paymentItem.setAmount(itemPriceTotal);
Iterator<?> taxIterator<?> = orderItemDetail.getOrderDetailTaxes().iterator();
float taxAmount = 0;
while (taxIterator.hasNext()) {
OrderDetailTax orderItemTax = (OrderDetailTax) taxIterator.next();
taxAmount += orderItemTax.getTaxAmount();
}
BasicAmountType itemTaxTotal = new BasicAmountType();
itemTaxTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
itemTaxTotal.set_value(Format.getFloat(taxAmount));
paymentItem.setTax(itemTaxTotal);
paymentItems.add(paymentItem);
}
float shippingAmount = orderHeader.getShippingTotal() - orderHeader.getShippingDiscountTotal();
if (shippingAmount > 0) {
PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();
paymentItem.setName("Shipping");
paymentItem.setNumber("");
paymentItem.setQuantity(BigInteger.valueOf((long) 1));
BasicAmountType itemPriceTotal = new BasicAmountType();
itemPriceTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
itemPriceTotal.set_value(Format.getFloatObj(shippingAmount));
paymentItem.setAmount(itemPriceTotal);
Iterator<?> taxIterator<?> = orderHeader.getOrderTaxes().iterator();
float taxAmount = 0;
while (taxIterator.hasNext()) {
OrderDetailTax orderItemTax = (OrderDetailTax) taxIterator.next();
if (orderItemTax.getOrderItemDetail() != null) {
continue;
}
taxAmount += orderItemTax.getTaxAmount();
}
BasicAmountType itemTaxTotal = new BasicAmountType();
itemTaxTotal.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
itemTaxTotal.set_value(Format.getFloat(taxAmount));
paymentItem.setTax(itemTaxTotal);
paymentItems.add(paymentItem);
}
PaymentDetailsItemType paymentDetailsItemTypes[] = new PaymentDetailsItemType[paymentItems.size()];
paymentItems.copyInto(paymentDetailsItemTypes);
*/
// paymentDetail.setPaymentDetailsItem(paymentDetailsItemTypes);
detail.setPaymentDetails(0, paymentDetail);
// detail.setPaymentDetails(paymentDetail);
request.setDoExpressCheckoutPaymentRequestDetails(detail);
DoExpressCheckoutPaymentResponseType response = (DoExpressCheckoutPaymentResponseType) caller.call("DoExpressCheckoutPayment", request);
if (!response.getAck().equals(AckCodeType.Success)) {
throw new PaymentException(formatErrorMessage(response));
}
// authCode = response.getDoExpressCheckoutPaymentResponseDetails().getPaymentInfo().getTransactionID();