Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Dec 15, 2014
2 parents aefd615 + ff3ee47 commit f24b888
Show file tree
Hide file tree
Showing 15 changed files with 462 additions and 24 deletions.
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- hhvm

env:
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1
- WP_VERSION=3.5.1 WP_MULTISITE=0
- WP_VERSION=3.5.1 WP_MULTISITE=1

before_script:
- composer install
- wget https://raw.githubusercontent.com/wp-cli/sample-plugin/master/bin/install-wp-tests.sh
- bash install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION

after_script:
- php vendor/bin/coveralls
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## 1.0.0
* First release.
54 changes: 54 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = function( grunt ) {
// Project configuration.
grunt.initConfig( {
// Package
pkg: grunt.file.readJSON( 'package.json' ),

// JSHint
jshint: {
all: [ 'Gruntfile.js', 'composer.json', 'package.json' ]
},

// PHP Code Sniffer
phpcs: {
application: {
dir: [ 'src', 'tests' ],
},
options: {
standard: 'phpcs.ruleset.xml',
extensions: 'php',
ignore: 'node_modules'
}
},

// PHPLint
phplint: {
options: {
phpArgs: {
'-lf': null
}
},
all: [ 'src/**/*.php', 'tests/**/*.php' ]
},

// PHP Mess Detector
phpmd: {
application: {
dir: 'src'
},
options: {
exclude: 'node_modules',
reportFormat: 'xml',
rulesets: 'phpmd.ruleset.xml'
}
},
} );

grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-phpcs' );
grunt.loadNpmTasks( 'grunt-phplint' );
grunt.loadNpmTasks( 'grunt-phpmd' );

// Default task(s).
grunt.registerTask( 'default', [ 'jshint', 'phplint', 'phpmd', 'phpcs' ] );
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

## Documentation

* [Pay.nl](https://www.pay.nl/)
* [Paynl - Handleiding transactie API V1](http://pronamic.nl/wp-content/uploads/2014/09/Paynl-Handleiding-transactie-API-V1.pdf)
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "pay-nl",
"version": "1.0.0",
"description": "Pay.nl driver for the WordPress payment processing library.",
"repository": {
"type": "git",
"url": "https://github.com/wp-pay-gateways/pay-nl"
},
"keywords": [
"wordpress",
"wp",
"pay",
"pay-nl",
"ideal",
"gateway",
"pronamic"
],
"author": {
"name": "Pronamic",
"email": "info@pronamic.nl",
"url": "http://www.pronamic.nl/"
},
"contributors": [
{
"name": "Remco Tolsma",
"email": "info@remcotolsma.nl",
"url": "http://www.remcotolsma.nl/"
}
],
"license": "GPL",
"bugs": {
"url": "https://github.com/wp-pay-gateways/pay-nl/issues"
},
"homepage": "http://www.wp-pay.org/gateways/pay-nl/",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-phplint": "0.0.5",
"grunt-phpmd": "^0.1.1",
"grunt-phpcs": "^0.2.3",
"grunt-contrib-jshint": "^0.10.0"
}
}
8 changes: 8 additions & 0 deletions phpcs.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="WordPress Pay Pay.nl rules">
<rule ref="WordPress">
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
<exclude name="WordPress.VIP.RestrictedFunctions.wp_remote_get" />
</rule>
</ruleset>
22 changes: 22 additions & 0 deletions phpmd.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>

<ruleset name="WordPress Pay Pay.nl rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess" />
</rule>

<rule ref="rulesets/codesize.xml" />

<rule ref="rulesets/design.xml" />

<rule ref="rulesets/naming.xml" />

<rule ref="rulesets/unusedcode.xml">
<exclude name="UnusedFormalParameter" />
</rule>
</ruleset>
123 changes: 114 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,58 @@
* @version 1.0.0
*/
class Pronamic_WP_Pay_Gateways_PayNL_Client {
/**
* API URL
*
* @var string
*/
const API_URL = 'https://rest-api.pay.nl/%s/%s/%s/%s/';

/////////////////////////////////////////////////

/**
* Error
*
* @var WP_Error
*/
private $error;

/////////////////////////////////////////////////

/**
* Construct and initialize an Pay.nl client
*
* @param string $token
* @param string $service_id
*/
public function __construct( $token, $service_id ) {
$this->token = $token;
$this->token = $token;
$this->service_id = $service_id;
}

/////////////////////////////////////////////////

public function get_urL( $version, $namespace, $method, $output, $parameters = array() ) {
/**
* Get latest error
*
* @return WP_Error
*/
public function get_error() {
return $this->error;
}

/////////////////////////////////////////////////

/**
* Get Pay.nl API URL
*
* @param string $version
* @param string $namespace
* @param string $method
* @param string $output
* @param array $parameters
*/
private function get_url( $version, $namespace, $method, $output, $parameters = array() ) {
return add_query_arg( $parameters, sprintf(
self::API_URL,
$version,
Expand All @@ -36,7 +70,46 @@ public function get_urL( $version, $namespace, $method, $output, $parameters = a
) );
}

public function start_transaction( $amount, $ip_address, $finish_url ) {
/////////////////////////////////////////////////

/**
* Parse reponse
*
* @param stdClass $data
* @return Ambigous <NULL, stdClass>
*/
private function parse_response( $data ) {
$result = null;

if ( isset( $data, $data->request, $data->request->result ) ) {
if ( 0 == $data->request->result && isset( $data->request->errorId, $data->request->errorMessage ) ) {
$pay_nl_error = new Pronamic_WP_Pay_Gateways_PayNL_Error( $data->request->errorId, $data->request->errorMessage );

$this->error = new WP_Error( 'pay_nl_error', (string) $pay_nl_error, $pay_nl_error );
}

$result = $data;
}

return $result;
}

/////////////////////////////////////////////////

/**
* Transaction start
*
* @param float $amount
* @param string $ip_address
* @param string $finish_url
* @return stdClass
*
* @see https://admin.pay.nl/docpanel/api/Transaction/start/4
*/
public function transaction_start( $amount, $ip_address, $finish_url ) {
$result = null;

// URL
$url = $this->get_url( 'v4', 'Transaction', 'start', 'json', array(
'token' => $this->token,
'serviceId' => $this->service_id,
Expand All @@ -45,17 +118,49 @@ public function start_transaction( $amount, $ip_address, $finish_url ) {
'finishUrl' => $finish_url,
) );

// Request
$response = wp_remote_get( $url );

if ( 200 == wp_remote_retrieve_response_code( $response ) ) {
$body = wp_remote_retrieve_body( $response );

$data = json_decode( $body );

$result = $this->parse_response( $data );
}

$result = wp_remote_get( $url );
// Return
return $result;
}

if ( 200 == wp_remote_retrieve_response_code( $result ) ) {
$body = wp_remote_retrieve_body( $result );
/**
* Transaction info
*
* @param string $transaction_id
*
* @see https://admin.pay.nl/docpanel/api/Transaction/info/4
*/
public function transaction_info( $transaction_id ) {
$result = null;

// URL
$url = $this->get_url( 'v4', 'Transaction', 'info', 'json', array(
'token' => $this->token,
'transactionId' => $transaction_id,
) );

// Request
$response = wp_remote_get( $url );

if ( 200 == wp_remote_retrieve_response_code( $response ) ) {
$body = wp_remote_retrieve_body( $response );

$data = json_decode( $body );

if ( isset( $data, $data->request, $data->request->result ) ) {
var_dump( $data );
}
$result = $this->parse_response( $data );
}

// Return
return $result;
}
}
53 changes: 53 additions & 0 deletions src/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Title: Pay.nl error
* Description:
* Copyright: Copyright (c) 2005 - 2014
* Company: Pronamic
* @author Remco Tolsma
* @version 1.0.0
*/
class Pronamic_WP_Pay_Gateways_PayNL_Error {
/**
* Pay.nl error ID
*
* @var string
*/
private $id;

/**
* Pay.nl error message
*
* @var string
*/
private $message;

/////////////////////////////////////////////////

/**
* Constructs and initializes an Pay.nl error object
*
* @param string $id
* @param string $message
*/
public function __construct( $id, $message ) {
$this->id = $id;
$this->message = $message;
}

//////////////////////////////////////////////////

// @todo getters and setters

//////////////////////////////////////////////////

/**
* Create an string representation of this object
*
* @return string
*/
public function __toString() {
return $this->id . ' ' . $this->message;
}
}

0 comments on commit f24b888

Please sign in to comment.