Dealing with sold out products and the PayPal BMSetInventory API method

I’ve just built a WordPress custom post type which allows you to sell a few simple products on your site by interacting with the PayPal Button Management API. (It wasn’t easy. PayPal’s documentation is full of duplicated informal, distributed all over the place, and badly maintained.) One thing which isn’t mentioned in the documentation is that you can use the BMSetInventory API method to stop customers buying products when they are sold out… which is kind of critical, when you think of it.

It’s as simple as adding the SOLDOUTURL field to the request, so the fields are like so:

    [USER] => {API User}
    [PWD] => {API Password}
    [SIGNATURE] => {API Signature}
    [VERSION] => 63.0
    [METHOD] => BMSetInventory
    [HOSTEDBUTTONID] => {The ID of the button you want to affect}
    [TRACKINV] => {Either 1 or 0}
    [TRACKPNL] => {Either 1 or 0}
    [ITEMQTY] => {Stock level}
    [ITEMALERT] => {When to alert admin of stock level}
    [SOLDOUTURL] => http://example.com/shop/?soldout_id={ID}

You should get a reply which looks something like this:

    [TIMESTAMP] => 2011-08-27T13:25:57Z
    [CORRELATIONID] => df5555097d084
    [ACK] => Success
    [VERSION] => 63.0
    [BUILD] => 2075688

Then when you next use BMGetInventory you’ll see something like this:

    [HOSTEDBUTTONID] => VNP6FQ36QWJRL
    [TRACKINV] => 1
    [TRACKPNL] => 0
    [ITEMNUMBER] => 1
    [ITEMQTY] => 0
    [ITEMALERT] => 0
    [SOLDOUTURL] => http://cata.simonwheatley.co.uk/sold-out/27218
    [TIMESTAMP] => 2011-08-27T13:26:03Z
    [CORRELATIONID] => 881f28e87d8af
    [ACK] => Success
    [VERSION] => 63.0
    [BUILD] => 2075688

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>