November 22, 2008, Saturday, 326

BTPWS-WebBuy

From DBWiki

Jump to: navigation, search

Secure XML-API WebBuy Service

Some other functions, like WebBuy, can be performed via Bitmunk's secure xml-api web service. All HTTP requests to this service must use the POST method and SSL (https). Failure to do so will result in the service returning an exception in xml format.

Every specific service offered by the secure xml-api web service requires a Bitmunk username and loginKey.

WebBuy Get Contract Example

WebBuy contracts can be created through Bitmunk's secure xml-api service. Once a WebBuy contract has been created, a WebBuy purchase can be made. This method will only create a new contract, it will not accept it and therefore no funds or media will be transferred.

https://www.sandbox.bitmunk.com:9443/api/xml/secure/webbuy/getcontract

Your POST request should contain the following URL-encoded parameters:

  • username - The username for the Bitmunk user that wants to WebBuy.
  • loginKey - The user's current loginKey.
  • mediaId - The ID of the media the user wants to WebBuy.
  • accountId - (Optional) The ID of the Bitmunk financial account the user wants to make the purchase with. If the accountId is not provided then the user's first financial account will be used.

The formatted POST request should look like this:

POST /api/xml/secure/webbuy/getcontract HTTP/1.1
Host: www.sandbox.bitmunk.com:9443
Content-Type: application/x-www-form-urlencoded
Content-Length: 71

username=myusername&loginKey=9afd732c6&mediaId=6491443&accountId=12345

The following XML will be returned to you:

<?xml version="1.0" encoding="UTF-8"?>
<xml_response version="1.0">
 <contract version="2.0" id="2007033056087001582">
  <status state="none" error="none" message="ok"/>
  <buyer version="2.0" id="32074" username="fakeuser">
   <ip>0.0.0.0</ip>
   <financial_account version="2.0" id="41068" owner="32074">
    <description>fakeuser financial account</description>
    <amount version="2.0" currency="USD">95.3109797</amount>
   </financial_account>
  </buyer>
  <seller version="2.0" id="220" username="">
   <server>Bitmunk Internal Sales Server</server>
   <uri>https://sales.sandbox.bitmunk.com:9120/bss/</uri>
   <rating>3.0,2.0</rating>
  </seller>
  <manifest version="2.0">
   <ware version="2.0" id="6491443">
    <digital_work version="2.0">
     <media_info version="2.0" id="6491443" type="audio_song">
      <owner_id>32073</owner_id>
      <sellable>true</sellable>
      <status>claimed</status>
      <creator>Bitmunk Squad</creator>
      <title>Bitmunk Squad Theme Song</title>
      <sample_range>10:40</sample_range>
      <parent_media_ids/>
      <child_media_ids/>
      <details>
       <search_genre_id>0</search_genre_id>
       <banned_countries/>
       <mixed_albums/>
       <distribution_formats>mp3-bmwm</distribution_formats>
       <length>0</length>
       <publisher_description_id>0</publisher_description_id>
       <category>audio</category>
       <release_date>2007-01-12</release_date>
       <artist>Bitmunk Squad</artist>
       <publisher>Bitmunk Industrial Recording
1 Bitmunk Offices
Blacksburg VA, 24060</publisher>
       <isrc/>
       <composer_description_id>0</composer_description_id>
       <audio_albums/>
       <long_description>This song is a test song for purchase on our sandbox open source server.</long_description>
       <composer/>
       <short_description>This song is a test song for purchase.</short_description>
       <creator_description_id>0</creator_description_id>
       <track>1</track>
       <content_rating>not_rated</content_rating>
       <genre>null</genre>
       <picture_id>0</picture_id>
       <cover_song>false</cover_song>
       <licenses>sc,sc-p2p,sc-wb</licenses>
      </details>
      <royalties>
       <payee version="2.0" id="41067">
        <amount version="2.0" currency="USD">0.4960000</amount>
        <source>sva</source>
        <reason>Bitmunk Squad Artist Royalty</reason>
        <media_id>6491443</media_id>
       </payee>
       <payee version="2.0" id="1032">
        <amount version="2.0" currency="USD">0.0535000</amount>
        <source>Bitmunk Records</source>
        <reason>Music Label Digital Distribution Fee</reason>
        <media_id>6491443</media_id>
       </payee>
      </royalties>
     </media_info>
     <file_info version="2.0" id="FID6491443mp3">
      <name></name>
      <type>audio_song</type>
      <format>mp3</format>
      <size>2910208</size>
      <bitrate>0</bitrate>
      <uri/>
      <transferred>false</transferred>
      <dkey algorithm=""/>
     </file_info>
    </digital_work>
    <payee version="2.0" id="41067">
     <amount version="2.0" currency="USD">0.4960000</amount>
     <source>sva</source>
     <reason>Bitmunk Squad Artist Royalty</reason>
     <media_id>6491443</media_id>
    </payee>
    <payee version="2.0" id="1032">
     <amount version="2.0" currency="USD">0.0535000</amount>
     <source>Bitmunk Records</source>
     <reason>Music Label Digital Distribution Fee</reason>
     <media_id>6491443</media_id>
    </payee>
    <payee version="2.0" id="2">
     <amount version="2.0" currency="USD">0.0836969</amount>
     <source>Bitmunk Internal Sales Server</source>
     <reason>Sale Price</reason>
     <media_id>6491443</media_id>
    </payee>
    <payee version="2.0" id="1">
     <amount version="2.0" currency="USD">0.1500000</amount>
     <source>SVA</source>
     <reason>Bitmunk transaction fee: 0.15 cents</reason>
     <media_id>0</media_id>
    </payee>
   </ware>
  </manifest>
 </contract>
</xml_response>

The above contract can be used to make a WebBuy purchase, as explained in the next step.

WebBuy Purchase Example

To confirm a WebBuy purchase a WebBuy contract must be accepted. The following method demonstrates how this is done. Completing a WebBuy purchase will result in the transfer of funds. If this is done on the sandbox server, these funds will be fake :) and so will be the media that is purchased.

https://www.sandbox.bitmunk.com:9443/api/xml/secure/webbuy/purchase

Your POST request should contain the following URL-encoded parameters:

  • username - The username for the Bitmunk user that wants to WebBuy.
  • loginKey - The user's current loginKey.
  • contractId - The ID of the contract the user wants to accept.

The formatted POST request should look like this:

POST /api/xml/secure/webbuy/purchase HTTP/1.1
Host: www.sandbox.bitmunk.com:9443
Content-Type: application/x-www-form-urlencoded
Content-Length: 70

username=myusername&loginKey=9afd732c6&contractId=2007033056087001582

The following XML will be returned to you:

<?xml version="1.0" encoding="UTF-8"?>
<xml_response version="1.0">
 <uri>https://sales.sandbox.bitmunk.com:19120/bss/webbuy/32074/2007033056087001582</uri>
</xml_response>

Performing a GET on the returned URL will return a ZIP file with the media that was purchased.