@Test public void convertToCallbackRefund() throws Exception { gateway = new PayPalButtonPaymentGatewayImpl() { @Override protected IPNMessage createIPNMessage(final Map<String, String[]> requestParams) { return new IPNMessage(requestParams, Collections.emptyMap()) { @Override public boolean validate() { return true; } }; } }; final Map<String, String[]> callBackresult = getRefundParameters(); final CallbackAware.Callback callback = gateway.convertToCallback(callBackresult, false); assertNotNull(callback); assertEquals(CallbackAware.CallbackOperation.REFUND, callback.getOperation()); assertEquals(new BigDecimal("43.70"), callback.getAmount()); assertEquals("171130110742-63", callback.getOrderGuid()); assertTrue(callback.isValidated()); }
@Override public Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing) { final IPNMessage ipn = createIPNMessage(privateCallBackParameters); final boolean valid = ipn.validate(); if (valid || forceProcessing) { if (valid) { LOG.debug("Signature is valid"); } else { LOG.warn("Signature is not valid ... forced processing"); } final String invoice = ipn.getIpnValue("invoice"); final String paymentStatus = ipn.getIpnValue("payment_status"); final boolean refund = "Refunded".equalsIgnoreCase(paymentStatus); BigDecimal callbackAmount = null; try { callbackAmount = new BigDecimal(ipn.getIpnValue("mc_gross")); if (refund && callbackAmount.compareTo(BigDecimal.ZERO) < 0) { callbackAmount = callbackAmount.negate(); } } catch (Exception exp) { LOG.error("Callback for {} did not have a valid amount {}", invoice, ipn.getIpnValue("mc_gross")); } if (StringUtils.isBlank(invoice)) { return new BasicCallbackInfoImpl( ipn.getIpnValue("custom"), refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } return new BasicCallbackInfoImpl( invoice, refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } else { LOG.debug("Signature is not valid"); } return new BasicCallbackInfoImpl( null, CallbackOperation.INVALID, null, privateCallBackParameters, valid ); }
PayPalButtonPaymentGatewayImpl extends AbstractPayPalPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing) { final IPNMessage ipn = createIPNMessage(privateCallBackParameters); final boolean valid = ipn.validate(); if (valid || forceProcessing) { if (valid) { LOG.debug("Signature is valid"); } else { LOG.warn("Signature is not valid ... forced processing"); } final String invoice = ipn.getIpnValue("invoice"); final String paymentStatus = ipn.getIpnValue("payment_status"); final boolean refund = "Refunded".equalsIgnoreCase(paymentStatus); BigDecimal callbackAmount = null; try { callbackAmount = new BigDecimal(ipn.getIpnValue("mc_gross")); if (refund && callbackAmount.compareTo(BigDecimal.ZERO) < 0) { callbackAmount = callbackAmount.negate(); } } catch (Exception exp) { LOG.error("Callback for {} did not have a valid amount {}", invoice, ipn.getIpnValue("mc_gross")); } if (StringUtils.isBlank(invoice)) { return new BasicCallbackInfoImpl( ipn.getIpnValue("custom"), refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } return new BasicCallbackInfoImpl( invoice, refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } else { LOG.debug("Signature is not valid"); } return new BasicCallbackInfoImpl( null, CallbackOperation.INVALID, null, privateCallBackParameters, valid ); } }
PayPalButtonPaymentGatewayImpl extends AbstractPayPalPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing) { final IPNMessage ipn = createIPNMessage(privateCallBackParameters); final boolean valid = ipn.validate(); if (valid || forceProcessing) { if (valid) { LOG.debug("Signature is valid"); } else { LOG.warn("Signature is not valid ... forced processing"); } final String invoice = ipn.getIpnValue("invoice"); final String paymentStatus = ipn.getIpnValue("payment_status"); final boolean refund = "Refunded".equalsIgnoreCase(paymentStatus); BigDecimal callbackAmount = null; try { callbackAmount = new BigDecimal(ipn.getIpnValue("mc_gross")); if (refund && callbackAmount.compareTo(BigDecimal.ZERO) < 0) { callbackAmount = callbackAmount.negate(); } } catch (Exception exp) { LOG.error("Callback for {} did not have a valid amount {}", invoice, ipn.getIpnValue("mc_gross")); } if (StringUtils.isBlank(invoice)) { return new BasicCallbackInfoImpl( ipn.getIpnValue("custom"), refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } return new BasicCallbackInfoImpl( invoice, refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } else { LOG.debug("Signature is not valid"); } return new BasicCallbackInfoImpl( null, CallbackOperation.INVALID, null, privateCallBackParameters, valid ); }  }
PayPalButtonPaymentGatewayImpl extends AbstractPayPalPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing) { final IPNMessage ipn = createIPNMessage(privateCallBackParameters); final boolean valid = ipn.validate(); if (valid || forceProcessing) { if (valid) { LOG.debug("Signature is valid"); } else { LOG.warn("Signature is not valid ... forced processing"); } final String invoice = ipn.getIpnValue("invoice"); final String paymentStatus = ipn.getIpnValue("payment_status"); final boolean refund = "Refunded".equalsIgnoreCase(paymentStatus); BigDecimal callbackAmount = null; try { callbackAmount = new BigDecimal(ipn.getIpnValue("mc_gross")); if (refund && callbackAmount.compareTo(BigDecimal.ZERO) < 0) { callbackAmount = callbackAmount.negate(); } } catch (Exception exp) { LOG.error("Callback for {} did not have a valid amount {}", invoice, ipn.getIpnValue("mc_gross")); } if (StringUtils.isBlank(invoice)) { return new BasicCallbackInfoImpl( ipn.getIpnValue("custom"), refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } return new BasicCallbackInfoImpl( invoice, refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } else { LOG.debug("Signature is not valid"); } return new BasicCallbackInfoImpl( null, CallbackOperation.INVALID, null, privateCallBackParameters, valid ); }  @Override String getPostActionUrl(); @Override String getSubmitButton(final String locale); @Override Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing); @Override CallbackAware.CallbackResult getExternalCallbackResult(final Map<String, String> callbackResult,
                                                                  final boolean forceProcessing); @Override void preProcess(final Payment payment, final Callback callback, final String processorOperation); @Override void postProcess(final Payment payment, final Callback callback, final String processorOperation); @Override Payment authorizeCapture(final Payment payment, final boolean forceProcessing); @Override Payment authorize(final Payment paymentIn, final boolean forceProcessing); @Override Payment reverseAuthorization(final Payment paymentIn, final boolean forceProcessing); @Override Payment capture(final Payment paymentIn, final boolean forceProcessing); @Override Payment voidCapture(final Payment paymentIn, final boolean forceProcessing); @Override Payment refund(final Payment paymentIn, final boolean forceProcessing); @Override String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment); @Override Payment createPaymentPrototype(final String operation,
                                          final Map map,
                                          final boolean forceProcessing); @Override PaymentGatewayFeature getPaymentGatewayFeatures(); }
PayPalButtonPaymentGatewayImpl extends AbstractPayPalPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing) { final IPNMessage ipn = createIPNMessage(privateCallBackParameters); final boolean valid = ipn.validate(); if (valid || forceProcessing) { if (valid) { LOG.debug("Signature is valid"); } else { LOG.warn("Signature is not valid ... forced processing"); } final String invoice = ipn.getIpnValue("invoice"); final String paymentStatus = ipn.getIpnValue("payment_status"); final boolean refund = "Refunded".equalsIgnoreCase(paymentStatus); BigDecimal callbackAmount = null; try { callbackAmount = new BigDecimal(ipn.getIpnValue("mc_gross")); if (refund && callbackAmount.compareTo(BigDecimal.ZERO) < 0) { callbackAmount = callbackAmount.negate(); } } catch (Exception exp) { LOG.error("Callback for {} did not have a valid amount {}", invoice, ipn.getIpnValue("mc_gross")); } if (StringUtils.isBlank(invoice)) { return new BasicCallbackInfoImpl( ipn.getIpnValue("custom"), refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } return new BasicCallbackInfoImpl( invoice, refund ? CallbackOperation.REFUND : CallbackOperation.PAYMENT, callbackAmount, privateCallBackParameters, valid ); } else { LOG.debug("Signature is not valid"); } return new BasicCallbackInfoImpl( null, CallbackOperation.INVALID, null, privateCallBackParameters, valid ); }  @Override String getPostActionUrl(); @Override String getSubmitButton(final String locale); @Override Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing); @Override CallbackAware.CallbackResult getExternalCallbackResult(final Map<String, String> callbackResult,
                                                                  final boolean forceProcessing); @Override void preProcess(final Payment payment, final Callback callback, final String processorOperation); @Override void postProcess(final Payment payment, final Callback callback, final String processorOperation); @Override Payment authorizeCapture(final Payment payment, final boolean forceProcessing); @Override Payment authorize(final Payment paymentIn, final boolean forceProcessing); @Override Payment reverseAuthorization(final Payment paymentIn, final boolean forceProcessing); @Override Payment capture(final Payment paymentIn, final boolean forceProcessing); @Override Payment voidCapture(final Payment paymentIn, final boolean forceProcessing); @Override Payment refund(final Payment paymentIn, final boolean forceProcessing); @Override String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment); @Override Payment createPaymentPrototype(final String operation,
                                          final Map map,
                                          final boolean forceProcessing); @Override PaymentGatewayFeature getPaymentGatewayFeatures();  }