To start off, we are going to work in “staging” mode. What this means is its for testing only and when you run a transaction it will not actually charge anything it will just let you test everything out.

“Production” mode is when everything is running live and you want to charge cards.

When registering applications with WePay you have to understand staging and production are completely separate. This also means your API credentials are 100% completely different from staging to production. So when moving from one to the other you need to change your information as well as the account id!

This how to assumes you already have an account. Again if you registered at www.wepay.com you still have to register at stage.wepay.com because they are separate sites.

1. Go to stage.wepay.com and login.

2. Once logged in go to https://stage.wepay.com/developer

3. Click on “Register an Application”

4.  Fill in the account information

5. Submit and you will be brought to a page like I have below. For security reasons I have blanked out the account information.

 

As you can see you have the account id, access token, client id and client secret. This should be all the information you need to get your plugin working.

This how to is the same when you want to register for  production API credentials, but instead of going to http://stage.wepay.com, go to http://www.wepay.com

If your looking for a Wepay Plugin to your application, whatever it may be. Please feel free to contact me, I would be glad to help you build it or I can build it for you. Contact Me.

As you can tell I have already release 3 open source plugins into Wepay.

WordPress Wepay Plugin

OsCommerce Wepay Plugin

Zen-Cart Wepay Plugin

And I have more I’m working on! 🙂 Let me know if I can be of assistance.

Alright to get the OsCommerce Wepay Plugin working you will need API Access to Wepay. I decided to split this tutorial into part 1 and Part 2, Part 1 is how to get your API information and account id. Part 2 is the setup of the plugin. I’m only going into production mode. I don’t see the need to test it since the plugin has been tested. Also your plugin will not work till Wepay activates your API, if its pending, you will not be able to process transactions.

Lets get started.

 

Part 1. Getting your API information

1. First you will need to goto https://www.wepay.com/developer. That is the production site, which means you can start collecting money today.

2. Once you register you will need to go to the developer section again, click on “Your Apps”

3. Click on “Create an application”, fill out all the fields, and hit submit.

4. You now have registered a app with wepay, which will give you your client secret, access token.

5 . You will now need to create an account you want your money to go into. Click on the “Home” link at the top of the screen. This will bring you to your account home page. You can ether use an account you have created or create a new one. In this case I will use one I already have, so click on the one you want to use.

Once you have clicked on it, in the address bar on your browser will tell you your account number.

Example: https://www.wepay.com/group/view/<YOUR ACCOUNT NUMBER HERE>

Copy that number you have in your browser, you will need it later.

 

Part 2. Setting up the Plugin

1. Copy the folders “includes” and “ext” directly into your OsCommerce Installation.

2. Login to your admin and activate the payment module.

3. Once activated you will need to fill in all the data you got in step 1, your client id, client secret, account id, and access token.

4. Once you have filled in all the fields, you should now be using the payment module and it should be working with Wepay.

 

If you have issues contact me or post a comment.

Just about done with the WordPress Plugin, should be out this weekend yet.
What version 1.0 will do:

  • See you account balance
  • Create buttons for your users to make payments on using shortcodes. (Totally customizable, make the button any type.)
  • Settings Menu to control API information

IPN integration will not be in this version. Feel free to ask questions.

Its official, version 1.0 for both OsCommerce and Zen-Cart have been released. Both are designed to drag and drop right into the web installation. All you need is your API information and account ID.

You can download the OsCommerce version here: http://addons.oscommerce.com/info/8408

The Zen-Cart version is currently unavailable until they approve it from the add-ons site. For now you can download it from here directly. Download Zen-Cart Wepay Plugin

The regular checkout with Wepay is very simple and a little bit easier then the iframe method. You will need to download the Wepay SDK to use this method. Scroll to the end of this post and you will find a zip file with all the code in this tutorial plus the sdk file. This includes an IPN I wrote, it is identical to the one used in the iframe checkout. If you already have setup everything on Wepay (I.e. access token, client id, etc) go to step 6, otherwise start at the top.

Alright lets start with the checkout.

1. First you will need to go to https://stage.wepay.com/register. That is the staging site, which means you can run as many transactions through it for testing purposes only. You have to test your code in the staging environment before you can go live! You can also login if you already have login credentials to the staging site.

2. Once you register on the staging site you will want to go to this page: https://stage.wepay.com/developer/register

 

3. Select “Test Enviroment” to create an app for testing purposes only.

4. Now you will need to fill out the form with Application Name, Your home url (website url), and description of what your app will do when interacting with WePay. Read the entire terms of service before you check the box and submit.

5 . You should have a page with your API credentials which include:

– Account ID

– Access Token

– Client ID

– Client Secret

 

6. (This is only in PHP.) You will need the Wepay SDK. You can download it below. You will also need your client id, client secret, account id, and access token. All can be found on your applications registration page on WePay’s staging site. See the API Reference to find out what is required and what you can add to the call https://stage.wepay.com/developer/reference/checkout#create

<?php
//// Wepay API regular checkout
//// written by Alan Pinnt www.alanpinnt.com
//// 2012
 
require 'wepay.php';
 
$client_id = "<Your Client ID>";
$client_secret = "<Your Client Secret>";
$access_token = "<Your Client Token>";
$account_id = "<Your Accout ID>"; 
 
Wepay::useStaging($client_id, $client_secret);
$wepay = new WePay($access_token);
 
try {
$checkout = $wepay->request('/checkout/create', array(
'account_id' => $account_id, // ID of the account that you want the money to go to
'amount' => "1.00", // dollar amount you want to charge the user
'short_description' => "Short product description", // a short description of what the payment is for
'reference_id' => "123456", // A reference id for your application to use.
'type' => "GOODS", // the type of the payment - choose from GOODS SERVICE DONATION or PERSONAL
'mode' => "regular", // put iframe here if you want the checkout to be in an iframe, regular if you want the user to be sent to WePay
'fee_payer' => "Payee", // Here you put who is paying the fees you or your client. Payee = client, Payer = account holder
'redirect_uri' => "http://www.mysite.com/thanks.php", // The page where you want clients to go after the transaction is completed.
'callback_uri' => "http://www.mysite.com/wepayipn.php", // Location of the file that handles IPN requests
)
);
} catch (WePayException $e) { // if the API call returns an error, get the error message for display later
$error = $e->getMessage();}
header("Location: $checkout->checkout_uri"); ///redirect user to the payment page
?>

Make sure you put your access token, client id, client secret, and account id in the proper areas.

 

Step 7. The IPN file

<?php
//// Wepay IPN
//// written by Alan Pinnt www.alanpinnt.com
//// 2012
require 'wepay.php';
 
if (!empty($_POST['checkout_id'])) {$thecheckoutid = $_POST['checkout_id'];}
 
$client_id = "<Your Client ID>";
$client_secret = "<Your Client Secret>";
$access_token = "<Your Client Token>";
$account_id = "<Your Accout ID>"; 
 
/**
* Initialize the WePay SDK object
*/
Wepay::useStaging($client_id, $client_secret);
$wepay = new WePay($access_token);
 
/**
* Make the API request to get the checkout_uri
*
*/
try {
$checkout = $wepay->request('checkout', array(
'checkout_id' => $thecheckoutid, // ID of the account that you want the money to go to
)
);
} catch (WePayException $e) { // if the API call returns an error, get the error message for display later
$error = $e->getMessage();
}
 
///some things you might want to use. Delete this stuff otherwise///
print '<br /><br />';
print $checkout->short_description;
print '<br /><br />';
print $checkout->checkout_id;
print '<br /><br />';
print $checkout->reference_id;
print '<br /><br />';
print $checkout->gross;
print '<br /><br />';
print $checkout->payer_name;
////stop deleteing here///
 
	if ($checkout->state == "captured") {
	///do something here
        } elseif ($checkout->state == "authorized") {
	///do something here
        } elseif ($checkout->state == "cancelled") {
	///do something here
        } elseif ($checkout->state == "refunded") {
	///do something here
        } elseif ($checkout->state == "expired") {
	///do something here
        }
?>

You should now have working checkout with Wepay and have an IPN to update the payment status on your application.

Also if you have an error on your checkout that is similar to this:

SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Please see this post here to fix this issue.

All the code in this tutorial, click here to download all the files in this tutorial (Wepay SDK, checkout, and IPN)

SDK Download (wepay.php) : https://github.com/wepay/PHP-SDK/blob/master/wepay.php

Wepay API Reference Pages:

API Object States

Checkout API Calls

API Change Log

Feel free to comment and let me know if you need help.

*** UPDATED – 3/8/13 – Made changes since the site has changed so much since this was originally written. Also updated the downloadable zip of files with the latest WePay SDK.  ***

I have received a lot of email because of the wepay API tutorial I posted. To let everyone know, I’m working on posting a normal checkout as well. I have had a ton of requests for this and I will make sure I get it out this weekend.

As for the Oscommerce plugin, I’m almost done with it. I have some testing to do to confirm but it looks like it will release sooner then expected. I will post here as soon as the v1.0 rolls out.