braintree / braintree_java

Braintree Java library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
158 stars 98 forks source link

Request a test WebhookNotification from BraintreeGateway in sandbox mode #45

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'm currently discovering that Webhook-Testing is not very well supported yet.

I wonder if it would be possible to get a real Webhook message object from the BraintreeClient in the future.

Instead of sending the Webhook notification to a publicly visible server http://example.com/bt/subscription why not create it in the sandbox, receive it locally and then forward it to http://localhost:8080/bt/subscription?

private final static BraintreeGateway BT; // Gateway instance

public void subscriptionWentActiveTest() {

    // Create customer ..
    // Create payment method (credit card) ..
    // Create a subscription ..

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

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

    // Create and receive a webhook notification

    WebhookNotification webhookNotification = BT.webhookTesting()
            // Creates a 'real' fake notification having set all values
            // from the subscription, add-ons, etc.
            .createNotification(
                WebhookNotification.Kind.SUBSCRIPTION_WENT_ACTIVE, 
                subscription.getId()
            );

    // Forward the notification to the locally running server ..
    this.forwardNotification("/bt/subscription", webhookNotification);
}

Is something like this possible?

matthewarkin commented 8 years ago

One thing you can do is use a service like ngrok. That will give you a publicly routable url that will tunnel to your localhost.

ghost commented 8 years ago

@matthewarkin Hi! Yes, I'm now using it. I have to say ngrok works quite well but I was just wondering why the BraintreeGateway does not offer such a functionality. Maybe I imagine this as too simple and something like this is too much effort but on the other hand I see BT's awesome sandbox and it made me think why there isn't such a forward functionality :)

omgrr commented 8 years ago

Currently we don't have any plans to implement any kind of forwarding functionality.

We do have sample payloads that you can use to simulate the different types of webhooks your application might receive.

I'm going to to close this issue for now. If you need any additional help with your webhook testing I encourage you to reach out to support. Thanks!

yasir-rafiq commented 5 years ago

Hi can you mention how to use ngrok.

crookedneighbor commented 5 years ago

@yasir-rafiq please refer to the ngrok documentation https://ngrok.com/docs