java Easypost webhook退款事件

v6ylcynt  于 2023-05-05  发布在  Java
关注(0)|答案(1)|浏览(256)

我应该听什么webhook事件来知道运输标签的退款被承运人接受?
下面是我现在的做法,但不幸的是,当我在本地运行easypost webhook时,即使提交了退款,它也不会发出事件。我从未在statusDetail中获得'return_update'。下面是我的代码:

if (statusDetail.equals("status_update") || statusDetail.equals("out_for_delivery") || statusDetail.equals("arrived_at_destination")) {
    String easypostShipmentId = (String) result.get("shipmentId");

    Shipment userShipment = shipmentService.retrieveShipmentFromEasypostId(easypostShipmentId);

    if (statusDetail.equals("arrived_at_destination")) {
        userShipment.setEasypostStatus(EasypostShipmentStatus.DELIVERED);
        userShipment.setStatus(ShipmentStatus.DELIVERED);
        userShipment.setDeliveryDate(Instant.now());
    } else {
        String shipmentStatus = (String) result.get("status");
        userShipment.setEasypostStatus(EasypostShipmentStatus.valueOf(shipmentStatus.toUpperCase()));
        Long estDeliveryDateMillis = (Long) result.get("estDeliveryDate");
        userShipment.setDeliveryDate(Instant.ofEpochMilli(estDeliveryDateMillis));
    }

    shipmentService.updateShipment(userShipment);
    activityLoggerService.insert(userShipment.getUser(), userShipment, activityLoggerService.getShipmentStatusChangeMessage(userShipment), ActivityMessageType.STATUS_UPDATE);
} else if (statusDetail.equals("return_update")) {
    String easypostShipmentId = (String) result.get("shipmentId");
    Shipment userShipment = shipmentService.retrieveShipmentFromEasypostId(easypostShipmentId);
    String shipmentStatus = (String) result.get("status");

    String chargeId = userShipment.getStripeChargeId();
    try {
        // Refund successful
        Refund refund = stripeService.refund(chargeId);
        userShipment.setStripeRefundId(refund.getId());
        userShipment.setStatus(ShipmentStatus.REFUND_PROCESSED);
        userShipment.setEasypostStatus(EasypostShipmentStatus.valueOf(shipmentStatus.toUpperCase()));

        shipmentService.updateShipment(userShipment);
        double refundAmount = stripeService.getRefundAmount(refund);
        activityLoggerService.insert(userShipment.getUser(), userShipment, activityLoggerService.getShipmentReturnProcessed(userShipment, refundAmount), ActivityMessageType.RETURN_PROCESSED);
    } catch (StripeException e) {
        System.err.println("Error issuing refund: " + e.getMessage());
    }
}
waxmsbnn

waxmsbnn1#

当EasyPost后端成功处理退款时,会创建一个refund.successful事件。这种情况可能发生在申请退款后的几天或几周内。USPS特别需要15-30天的时间来退还标签。不幸的是,我不相信有一种方法可以在test环境中模拟这种行为。
https://www.easypost.com/docs/api#events
当非即时退款请求完成时,系统会创建一个“refund.successful”事件。美国邮政是最好的例子,这一点,因为美国邮政邮费需要15天以上的退款后,最初的退款创建。

相关问题