Due to the recent storms where I’m located, updates to the upcoming plugins and current ones have been delayed. Currently I reset all the updates to the 30th.We had 80mph straight line winds, some people reported 100mph, rain totals from 14 to 20 inches in 24 hours from two storms. It was coming down so hard I couldn’t see no more then 10 feet at most when the storm was at its peak. Power of course went out along with internet. So work got delayed. When the storm ended at 4:30AM it was like another place, a lot of the neighbors trees as well as ours were down. Lucky everyone was okay. Since then I was cutting up not only our trees put our neighbors as well. We had 4 spruce trees 30 years old taken down like twigs, Which I never thought I would see go while I was here. Funny thing about the whole deal was all the trees I wanted gone or I thought would have gone didn’t. All the ones I knew where healthy and I wanted them to stay, pretty much are gone at this point. Not much structural damage in town, few homes but not many. Honestly were really lucky.

The new WordPress WePay API is released and now available through the WordPress Plugin Directory. That plugin is extremely powerful and can do all the API calls to WePay from simple WordPress shortcodes. Meaning no writing code. I also included an IPN that can be customized to update the database. For more information see the WordPress WePay API Plugin.

I will be working as much as I can to get these updates and new plugins out asap.

 

Wepay, a great alternative to PayPal. They’re support at Wepay is phenomenal which in itself is a great reason to work with wepay. The API at wepay is very simple to use. In this case I have been using their SDK which makes the development much faster! In this tutorial I will show you the code to setup a iframe wepay checkout and an IPN to update your application database. I have attached a zip file of all the code ready to be used.

Alright lets start with the checkout.

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

2. Once you register on the staging site 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://stage.wepay.com/group/view/<YOUR ACCOUNT NUMBER HERE>

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

6. Alright now to the code. I have only set this up in PHP so when I get a chance I will do it in other languages. Keep in mind, you will need the Wepay SDK. You can download it below. You will also need your client id, client secret and access token. All can be found on your applications registration page on Wepay’s staging site. Your account id is the account you want to have the funds into, which you should have that account number from a minute ago.

require 'includes/wepay.php';
 
$client_id = "<YOUR CLIENT ID>";
$client_secret = "<YOUR CLIENT SECRET>";
$access_token = "<YOUR ACCESS TOKEN";
$account_id = "<YOUR ACCOUNT 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' => "Order id you want", // A reference id for your application to use.
'type' => "GOODS", // the type of the payment - choose from GOODS SERVICE DONATION or PERSONAL
'mode' => "iframe", // 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();
}

Where ever you want to display your Wepay iframe, here is the additional code you will need.

<div id="checkout_div"></div>

Before the </body> Place this javascript there.

<script type="text/javascript" src="https://stage.wepay.com/js/iframe.wepay.js"> </script>
<script type="text/javascript"> WePay.iframe_checkout("checkout_div", "<?php echo $checkout->checkout_uri ?>"); </script>

You now have a working Iframe checkout from Wepay. Next we will work on the IPN.

7. Here is the code you will need for your IPN:

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
        }

Pretty self explanatory, if you need more API object states, click here to see them all with explainations.

Now you have a working IPN and Iframe checkout in the staging environment. In my next tutorial I will post how to switch from staging to production.

Also if you have an error on your iframe 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 the IPN and Iframe Checkout with the SDK wepay file.

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.