[V1] Setting up Webhooks
You can use certain webhooks with PayWhirl to receive push notifications
Updated over a week ago

You can use certain webhooks with PayWhirl to receive push notifications. 

Certain third party applications will ask you to register your webhooks on PayWhirl. In order to do this, simple paste the webhook URL into the field provided.
 

Processing Webhooks

Note: You may need a developer's help to integrate your services with Paywhirl's webhooks.

Webhooks can be setup in the Webhooks section of your Paywhirl dashboard. You may include multiple webhooks under one account if you need to send them to multiple processing scripts or applications. Paywhirl's webhooks can be processed by your server-side scripting language of choice and can be used to interact with any 3rd party service via their API.

Common uses for webooks include processing orders with a fulfillment service, adding customer records to your website, or sending automated emails when an action occurs in your Paywhirl widget. Webhooks give you the flexibility to integrate Paywhirl with any other web service, including, but not limited to, your own website.

When we send you a webhook, we combine both the Paywhirl data collected for your customer and the original Stripe Webhook in its entirety, so its not necessary to register webhooks with both Paywhirl and Stripe.
 

Receiving a Webhook

Configuring your server to receive a new webhook is no different from creating any page on your website. With PHP, you might create a new .php file on your server; with a framework like Sinatra, you would add a new route with the desired URL. Remember, with webhooks, your server is the server receiving the request.

Webhook data is sent as JSON in the request's body. The full event details are included and can be used directly. Alternatively, the event is also available in the Stripe API. If security is a concern, or if it's important to confirm that Paywhirl sent the webhook, you should only use the ID sent in your webhook and should request the remaining details from the Stripe API directly. We also advise you to guard against replay-attacks by recording which events you receive, and never processing events twice.


PHP

// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
// Do something with $event_json
http_response_code(200); // PHP 5.4 or greater

PYTHON

import json
from django.http import HttpResponse

Using Django

def my_webhook_view(request):
  # Retrieve the request's body and parse it as JSON
  event_json = json.load(request.body)
  # Do something with event_json
  return HttpResponse(status=200)

RUBY

require "json"

Using Sinatra

post "/my/webhook/url" do
  # Retrieve the request's body and parse it as JSON
  event_json = JSON.parse(request.body.read)
  # Do something with event_json
  status 200
end

NODE.JS

// Using Express
app.post("/my/webhook/url", function(request, response) {
  // Retrieve the request's body and parse it as JSON
  var event_json = JSON.parse(request.body);
  // Do something with event_json
  response.send(200);
});


Example Webhook:

{
    "subscriber": {
        "profile": "",
        "city": "Santa Barbara",
        "first_name": "James",
        "last_name": "Bond",
        "user_id": "1",
        "zip": "93101",
        "admin": "0",
        "id": "193",
        "state": "CA",
        "address_1": "123 Easy St",
        "address_2": "Apt B",
        "date_created": "2014-08-29 18:31:00",
        "password": "e3b57875237253e91421cbaf8d4499b75676042c",
        "stripe_id": "cus_4gKWgRj8GwzeEa",
        "email": "james@yovigo.com",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Firefox/31.0"
    },
    "source": "paywhirl",
    "body": {
        "object": "event",
        "user_id": "acct_104JoC4rtR6PhAirrn",
        "pending_webhooks": 1,
        "created": 1409352443,
        "data": {
            "object": {
                "livemode": false,
                "currency": "usd",
                "invoice": "in_14Wy9rO4R6PhAirrnXPSGO8aR",
                "id": "ch_14Wy9O4R6rPhAirrnyv3Kdnup",
                "captured": true,
                "card": {
                    "address_line2": null,
                    "customer": "cus_4gKWgRrj8GwzeEa",
                    "address_city": null,
                    "exp_month": 1,
                    "funding": "credit",
                    "name": "James Bond",
                    "address_line1_check": null,
                    "country": "US",
                    "brand": "Visa",
                    "object": "card",
                    "cvc_check": null,
                    "address_zip": null,
                    "last4": "4242",
                    "address_line1": null,
                    "address_state": null,
                    "address_zip_check": null,
                    "exp_year": 2016,
                    "address_country": null,
                    "id": "card_14WxrWr4R6PhAirrn7CZux5zr",
                    "fingerprint": "PaNhcJWqsGrbnjuEe"
                },
                "balance_transaction": "txn_14Wy9P4R6rPhAirrnBh3jz7UF",
                "receipt_email": null,
                "dispute": null,
                "amount_refunded": 0,
                "description": null,
                "refunded": false,
                "object": "charge",
                "paid": true,
                "statement_description": null,
                "failure_code": null,
                "customer": "cus_4gKWgRjr8GwzeEa",
                "refunds": {
                    "has_more": false,
                    "total_count": 0,
                    "object": "list",
                    "data": [],
                    "url": "/v1/charges/ch_14Wy9O4rR6PhAirrnyv3Kdnup/refunds"
                },
                "created": 1409352442,
                "failure_message": null,
                "amount": 4500,
                "metadata": {}
            }
        },
        "livemode": false,
        "request": "iar_4gKpeHl6CcEfFy",
        "type": "charge.succeeded",
        "id": "evt_14Wy9P4R6PhAirrnprCIOLd1d"
    }
}

 

Did this answer your question?