Thursday, December 12, 2013

Bitcoin Classic ASP code example to create dynamic buy now button with custom price and description using coinbase.com API.

This code example shows you how to use the coinbase.com API to create a custom bitcoin buy now button using Classic ASP

Once you've created your coinbase.com account, you've probably seen how you can create buttons.  However, they require you to enter the price and item name at the time you create that button.

Many of us compute the product description and price at order time.   In that case, you need a way to create a custom Pay with Bitcoin button at the time of purchase that allows a dynamic price and item name and/or description.

Click Here to see a live example of a dynamically created Bitcoin buy now button

This is fairly easy to do in classic asp once you figure out how.  I start by showing the sample code.  You will need to activate your api key from within your coinbase.com account but for now, just look at the code example:

'================================
'Set UP the call to the coinbase API
'================================
dim sURLBC
dim sBCData
sURLBC = "https://coinbase.com/api/v1/buttons?api_key=xxxxxxYourAPIKeyfromCoinbasexxxxx"

'================================
'Your application computes product name, price and description
'================================
dim sName, sDescription, sPrice
sName = "Custom Product Name"
sDescription = "Custom product description"
sPrice = "29.95"  'custom product price.

'================================
'Add parameter data that will be used in a call to the coinbase api
'================================
sBCData = sBCData & "&" & server.urlencode("button[name]") & "=" & server.urlencode(sName)

sBCData = sBCData & "&" & server.urlencode("button[description]") & "=" & server.urlencode(sDescription)

sBCData = sBCData & "&" & server.urlencode("button[price_string]") & "=" & server.urlencode( sPrice )

sBCData = sBCData & "&" & server.urlencode("button[price_currency_iso]") & "=" & server.urlencode( "USD" )
               
               
dim sResponse 'response from the API
               
'===============================
'Call the API and get a response
'===============================       
dim objHTTPBitCoin
set objHTTPBitCoin = Server.CreateObject("MSXML2.ServerXMLHTTP")
objHTTPBitCoin.Open "POST", sURLBC
objHTTPBitCoin.setRequestHeader "User-Agent", "YOURSiteNAME/0.1"                
objHTTPBitCoin.setRequestHeader "content-type", "application/x-www-form-urlencoded"
objHTTPBitCoin.Send sBCData
sResponse =  objHTTPBitCoin.responseText
               
               
'===============================       
'Use this custom ParseString function to parse out the section where
'it gives us the code for the button that was just created.
'===============================       
dim sBCCode
sBCCode = ParseString(sResponse,"""code"":""","""")


'===============================       
'This is simply the javascript that you get from coinbase for a static button
' (look at more comments 'below the code).
'The response from the API gave us the button code sBCCode which is the substituted value for
'data-code=  This allows you to place this newly created button on your page.
'===============================                       
response.write "<a class=""coinbase-button"" data-code=""" & sBCCode & """ href=""https://coinbase.com/checkouts/""" _
    & sBCCode & """>Pay $" & formatnumber(sPrice ,2) & " USD With Bitcoin</a>" _
    & "<script src=""https://coinbase.com/assets/button.js"" type=""text/javascript""></script>"
   

'===============================       
'Function to parse out a string from a known begin and end point
'===============================       
Function ParseString(ByVal strIn , strfind , strend )
    On Error Resume Next
    Dim i1
    Dim i2
   
    ParseString = ""
   
    i1 = InStr(1, LCase(strIn), LCase(strfind))
    If i1 > 0 Then
        i1 = i1 + Len(strfind)
        i2 = InStr(i1, LCase(strIn), LCase(strend))
        If i2 > 0 Then
            ParseString = Mid(strIn, i1, i2 - i1)
        End If
    End If
    Err.Clear
End Function
           
When you get javascript to create a button on coinbase.com it looks like

In the Classic ASP script above, we're simply replacing the data-code with the one returned from the API call. 


To activate your API key:
  1.  login to coinbase.com
  2. On the left column under DEVELOPERS, click on Authentication
  3. This shows you a screen where you can enable your API key, change it, and show it.  
Once you have your API key, substitute it for our sample key shown in the code above.


Click Here to see a live example of a dynamicly created Bitcoin buy now button


Keys: Classic ASP, bitcoin, bitcoin custom button, dynamic price on button, Active Server Pages, VBScript, coinbase API

Monday, December 9, 2013

How do you set a discount coupon code percentage for the retail order purchase page.

First, login to your account

Next, Click the cart button (located across the top of the page):













Then, enter a discount coupon code and percentages:




Saturday, December 7, 2013

Minimum Payment

We reserve the right to charge a minimum payment.   This helps us offset the minimum fee costs we incur so we can continue to produce the product at the posted prices.

Paying more than you owe leaves a positive account balance in your TrepStar account that will be used to fund your future orders.

There are a few reasons why we may set a minimum payment:

  • If you don't order much, and you tend to order a single low cost item, which results in a small payment (less than $10.00).
  • Or, within a single session, you submit an order, then pay, then go back in and submit another order, then pay again etc...   The system was designed so you submit all of your orders first, then pay at the end.  

TrepStar incurs minimum transaction fees for each credit card, or paypal payment we accept.   Because of this fee, small payments cost us a lot more in terms of percentages.

We have chosen to require a minimum payment, rather than the alternative of charging the publisher the $0.30 transaction fee:

We pay 30 cents per transaction plus 2.9% of the total cost.  If all payments we received were $100.00 for example, it's not that bad.  It's $2.90 (the 2.9%) + $0.30  for the transaction fee for a total of  $3.20.  This is 3.2% of the total money collected.  We have roughly a 10% profit margin.  This means we paid 32% of our profit  just so we can take credit cards. This is very frustrating as it is... but it gets worse.

Unfortunately, if the payments are small, most if not all profit is used just to pay the credit card processor companies (visa/mc/amex and paypal...).

For example, if your payment is around $5.00,  we pay  $0.30 + 2.9% of $5.00 ($0.15).  That means we pay $0.45 on that $5.00 payment.  That's 9% in fees!

For small payments, we profit almost nothing, and can't keep competitive that way.

We realize you may be making only a few payments per week or month and 30 cents in fees doesn't sound like much but most of the payments we receive are from publishers who only submit a few orders per month.  That means the bulk of money we collect are payments less than $20.00.

REMEMBER:  A minimum payment results in a positive balance.  This means you will have a credit for future orders.  You don't lose any money.  You are just paying a little extra in advance which helps us spread out that transaction fee to a few orders.

If you are upset by having to pay a minimum payment, please email help@trepstar.com and explain your frustration.  We are just trying to find ways to keep prices low while still making enough money to continue.

TrepStar.com cdDVDfulfillment FAQ Help and Search

FAQ Help & Search
We produce your CD or DVD at order time.
These "On Demand", "Just in Time", "one off", "short run", CDs or DVDs will be mailed directly to your customers within 24 hours, and shipped to anywhere in the world.