1

我目前正在尝试创建一个测试 webhook-notification,如文档中所示:

HashMap<String, String> sampleNotification = gateway.webhookTesting().sampleNotification(
    WebhookNotification.Kind.SUBSCRIPTION_WENT_PAST_DUE, "my_id"
);

WebhookNotification webhookNotification = gateway.webhookNotification().parse(
    sampleNotification.get("bt_signature"),
    sampleNotification.get("bt_payload")
);

webhookNotification.getSubscription().getId();
// "my_id"

首先,我不知道my_id实际上应该是什么。它应该是计划ID吗?还是应该是Subscription身份证?

我已经测试了所有这些。我已将其设置为我的保险库中的现有计费计划,并且我还尝试创建一个如下Customer的实际值Subscription

public class WebhookChargedSuccessfullyLocal {

    private final static BraintreeGateway BT;

    static {
        String btConfig = "C:\\workspaces\\mz\\mz-server\\mz-web-server\\src\\main\\assembly\\dev\\braintree.properties";
        Braintree.initialize(btConfig);
        BT = Braintree.instance();
    }

    public static void main(String[] args) {

        WebhookChargedSuccessfullyLocal webhookChargedSuccessfullyLocal = new WebhookChargedSuccessfullyLocal();
        webhookChargedSuccessfullyLocal.post();
    }

    /**
     * 
     */
    public void post() {

        CustomerRequest customerRequest = new CustomerRequest()
                .firstName("Testuser")
                .lastName("Tester");

        Result<Customer> createUserResult = BT.customer().create(customerRequest);

        if(createUserResult.isSuccess() == false) {
            System.err.println("Could not create customer");
            System.exit(1);
        }

        Customer customer = createUserResult.getTarget();

        PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest()
                .customerId(customer.getId())
                .paymentMethodNonce("fake-valid-visa-nonce");

        Result<? extends PaymentMethod> createPaymentMethodResult = BT.paymentMethod().create(paymentMethodRequest);

        if(createPaymentMethodResult.isSuccess() == false) {
            System.err.println("Could not create payment method");
            System.exit(1);
        }

        if(!(createPaymentMethodResult.getTarget() instanceof CreditCard)) {
            System.err.println("Unexpected error. Result is not a credit card.");
            System.exit(1);
        }

        CreditCard creditCard = (CreditCard) createPaymentMethodResult.getTarget();

        SubscriptionRequest subscriptionRequest = new SubscriptionRequest()
                .paymentMethodToken(creditCard.getToken())
                .planId("mmb2");

        Result<Subscription> createSubscriptionResult = BT.subscription().create(subscriptionRequest);

        if(createSubscriptionResult.isSuccess() == false) {
            System.err.println("Could not create subscription");
            System.exit(1);
        }

        Subscription subscription = createSubscriptionResult.getTarget();

        HashMap<String, String> sampleNotification = BT.webhookTesting()
                .sampleNotification(WebhookNotification.Kind.SUBSCRIPTION_CHARGED_SUCCESSFULLY, subscription.getId());

        WebhookNotification webhookNotification = BT.webhookNotification()
                .parse(
                        sampleNotification.get("bt_signature"),
                        sampleNotification.get("bt_payload")
                        );

        System.out.println(webhookNotification.getSubscription().getId());

    }

}

但我得到的只是一个WebhookNotification没有设置的实例。似乎只设置了它的 ID 和时间戳,仅此而已。

我所期望的:

我希望收到一个Subscription对象,告诉我哪个客户订阅了它,以及计费计划中包含的所有附加组件。

有没有办法在沙盒模式下获得这样的测试通知?

4

1 回答 1

0

全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系支持人员

webhookNotification.getSubscription().getId();将返回与 关联的订阅的 ID sampleNotification,它可以是用于测试目的的任何内容,但在生产环境中将是 SubscriptionID。

接收来自的虚拟对象webhookTesting().sampleNotification()预期的行为,并且可以帮助您确保可以正确捕获各种 webhook。一旦该逻辑到位,您可以在设置 > Webhook 下的 Sandbox Gateway 中指定端点以接收真正的 Webhook 通知。

在这种情况下,SUBSCRIPTION_CHARGED_SUCCESSFULLY您确实会收到包含附加信息的Subscription 对象以及包含客户信息的Transaction 对象数组。

于 2016-08-15T18:11:52.673 回答