Visa Developer Center APIs
Access Visa Developer Center APIs
by Paul V. Biron/Sparrow Hawk Computing · github.com/pbiron/wp-visa-developer-center-apis
Install
The author publishes release zips, so WP-CLI can install straight from GitHub:
wp plugin install https://github.com/pbiron/wp-visa-developer-center-apis/releases/download/0.1.0/wp-visa-developer-center-apis.0.1.0.zipReadme
Visa Developer Center APIs
Contributors: pbiron
Tags: visa, visa developer center, rest api
Requires at least: 4.6
Tested up to: 5.3.2
Stable tag: 0.1.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Access Visa Developer Center APIs
Description
This plugin provides PHP classes that allows access to various Visa Developer Center (VDC) APIs.
As of version 0.1.0, 3 VDC APIs are supported:
Support for additional VDC APIs may or may not be added in future versions.
For example, to access the visacardeligibilityservices/v1/cardeligibility/validate endpoint, do something like the following:
<?php
use SHC\VDC\Card_Elibility_Service_API;
use SHC\VDC\APIException;
$api = new Card_Elibility_Service_API();
$postData = array(
'permenantAccountNumber' => 'The 16 digit credit card number to validate',
'vendorUniqueId' => 'The Vendor Unique ID from your project',
'correlationId' => 'A unique string to be used in subsequent calls to the "prepay" or "redeem" endpoints',
);
try {
// $response_data will be the JSON response from the API.
list( $response_data, $http_response_status, $http_response_headers ) = $api->validate( $postData );
// do something with the $response_data
}
catch ( InvalidArgumentException $ex ) {
// one or more required query params and/or postData params for the endpoint were not supplied.
// check $ex->getMessage() for the error message.
}
catch ( APIException $ex ) {
// check $ex->getMessage() for the error message from the API.
// In some cases, the API will return a stdClass object with additional error information. You can
// access that object with $ex->getResponseBody().
}
Before you can use the classes provided by this plugin, you will need to register and create a project at the Visa Developer Center.
Once you've created that project,
- copy the various SSL certs provided in the project to the
includes/certsdirectory - rename
includes/class-default-project-config.phptoincludes/class-project-config.php - edit
includes/class-project-config.phpand enter the project-specific info (e.g., theVendor Unique ID,Username,Password,Password,PrivateKeyPath, etc.).
In addition to classes for accessing these APIs, this plugin also provides WP-CLI commands for accessing the various endpoints the APIs provide.
For more information about the WP-CLI commands, do $ wp help vdc.
Important note: I have only tested this with projects that have the "Sandbox" status. If used in a live project, your mileage may vary.
TODOs
Important note: Because of the todos below, and many other reasons, I reserve the right to release future versions of this plugin that are not backwords compatible with this version!
Remove remnants of "Sample" Code
The Visa Developer Center provides some sample code for accessing their APIs. Naturally, I began by experimenting with that code. As with many codebases of that kind, I found that same code reallty hard to work with...and in many cases, buggy! So, I ditched most of it.
There are still 2 remnants of that sample code:
- The
API_ClientandApiExceptionclasses. These classes are a slight re-working of the equivalent classes in the sample code.- I do not like the fact that
API_Clientthrows exceptions and think I need to get rid of that - I want to replace the
API_Clientclass with calls to wp_remote_request(), etc.- I just haven't had time to figure out how to do the Two-Way SSL required by the APIs, using
wp_remote_post(), etc., but I don't think it will be hard.
- I just haven't had time to figure out how to do the Two-Way SSL required by the APIs, using
- I do not like the fact that
- The
Project_ConfigandConfigurationclasses. Again, these classes are a slight re-working of the equivalent classes in the sample code.- I need to figure out a better way to store the project-specific info
- I just haven't given it enough time to find a better solution
Storing/Accessing the project certs
There should be a more secure way of storing and/or allowing cUrl to access the project certs!
Also, the way things are now, when the next version of this plugin is released, WP's plugin update process will actually nuke your certs, which is not good! Will have to figure out how to avoid that!
Arguments to the WP-CLI commands
Many of the arguments for various API endpoints are in mixed-case, e.g., vendorUniqueId. Unfortunately, in WP-CLI <= 2.4.0, assoc_arg names are prohibited from containing uppercase characters :-( Therefore, any API param that contains uppercase characters is "spelled" slightly different when used as an argument to one of the WP-CLI commands.
For example,
vendorUniqueIdis spelledvendor_unique_id, etc
I've enquired whether a future version of WP-CLI could allow uppercase characters in assoc_arg names. We'll see how that goes.
Installation
From your WordPress dashboard
- Go to Plugins > Add New and click on Upload Plugin
- Upload the zip file
- Activate the plugin
Build from sources
- clone the global repo to your local machine
- install node.js and npm (instructions)
- install composer (instructions)
- run
npm update - run
composer install - run
grunt build- to build a new release zip
- run
grunt release
- run
- to build a new release zip
See Gruntfile.js for other grunt tasks that are defined.
Changelog
0.1.0
- init commit
Read the full README on GitHub →
Releases
| Tag | Published | Asset | Downloads |
|---|---|---|---|
| 0.1.0 | Jan 28, 2020 | wp-visa-developer-center-apis.0.1.0.zip | 3 |