Skip to content

Commit 2378678

Browse files
author
epriestley
committed
Add Balanced Payments API
Summary: Adds the Balanced PHP API to externals/. Ref T2787. Test Plan: Used in next diff. Reviewers: btrahan, chad Reviewed By: chad CC: aran, aurelijus Maniphest Tasks: T2787 Differential Revision: https://secure.phabricator.com/D5764
1 parent a8bc875 commit 2378678

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+7994
-0
lines changed

externals/balanced-php/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# composer
2+
.buildpath
3+
composer.lock
4+
composer.phar
5+
vendor
6+
*~
7+
*#
8+
# phar
9+
*.phar
10+
11+
# eclipse-pdt
12+
.settings
13+
.project
14+
*.iml

externals/balanced-php/.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: php
2+
before_script:
3+
- curl -s http://getcomposer.org/installer | php
4+
- php composer.phar install
5+
script: phpunit --bootstrap vendor/autoload.php --exclude-group suite tests/
6+
php:
7+
- 5.3
8+
- 5.4

externals/balanced-php/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2012 Balanced
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

externals/balanced-php/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Balanced
2+
3+
Online Marketplace Payments
4+
5+
[![Build Status](https://secure.travis-ci.org/balanced/balanced-php.png)](http://travis-ci.org/balanced/balanced-php)
6+
7+
The design of this library was heavily influenced by [Httpful](https://github.com/nategood/httpful).
8+
9+
## Requirements
10+
11+
- [PHP](http://www.php.net) >= 5.3 **with** [cURL](http://www.php.net/manual/en/curl.installation.php)
12+
- [RESTful](https://github.com/bninja/restful) >= 0.1
13+
- [Httpful](https://github.com/nategood/httpful) >= 0.1
14+
15+
## Issues
16+
17+
Please use appropriately tagged github [issues](https://github.com/balanced/balanced-php/issues) to request features or report bugs.
18+
19+
## Installation
20+
21+
You can install using [composer](#composer), a [phar](#phar) package or from [source](#source). Note that Balanced is [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) compliant:
22+
23+
### Composer
24+
25+
If you don't have Composer [install](http://getcomposer.org/doc/00-intro.md#installation) it:
26+
27+
$ curl -s https://getcomposer.org/installer | php
28+
29+
Add this to your `composer.json`:
30+
31+
{
32+
"require": {
33+
"balanced/balanced": "*"
34+
}
35+
}
36+
37+
Refresh your dependencies:
38+
39+
$ php composer.phar update
40+
41+
42+
Then make sure to `require` the autoloader and initialize all:
43+
44+
<?php
45+
require(__DIR__ . '/vendor/autoload.php');
46+
47+
\Httpful\Bootstrap::init();
48+
\RESTful\Bootstrap::init();
49+
\Balanced\Bootstrap::init();
50+
...
51+
52+
### Phar
53+
54+
Download an Httpful [phar](http://php.net/manual/en/book.phar.php) file, which are all [here](https://github.com/nategood/httpful/downloads):
55+
56+
$ curl -s -L -o httpful.phar https://github.com/downloads/nategood/httpful/httpful.phar
57+
58+
Download a RESTful [phar](http://php.net/manual/en/book.phar.php) file, which are all [here](https://github.com/bninja/restful/downloads):
59+
60+
$ curl -s -L -o restful.phar https://github.com/bninja/restful/downloads/restful.phar
61+
62+
Download a Balanced [phar](http://php.net/manual/en/book.phar.php) file, which are all [here](https://github.com/balanced/balanced-php/downloads):
63+
64+
$ curl -s -L -o balanced.phar https://github.com/balanced/balanced-php/downloads/balanced-{VERSION}.phar
65+
66+
And then `include` all:
67+
68+
<?php
69+
include(__DIR__ . '/httpful.phar');
70+
include(__DIR__ . '/restful.phar');
71+
include(__DIR__ . '/balanced.phar');
72+
...
73+
74+
### Source
75+
76+
Download [Httpful](https://github.com/nategood/httpful) source:
77+
78+
$ curl -s -L -o httpful.zip https://github.com/nategood/httpful/zipball/master;
79+
$ unzip httpful.zip; mv nategood-httpful* httpful; rm httpful.zip
80+
81+
Download [RESTful](https://github.com/bninja/restful) source:
82+
83+
$ curl -s -L -o restful.zip https://github.com/bninja/restful/zipball/master;
84+
$ unzip restful.zip; mv bninja-restful* restful; rm restful.zips
85+
86+
Download the Balanced source:
87+
88+
$ curl -s -L -o balanced.zip https://github.com/balanced/balanced-php/zipball/master
89+
$ unzip balanced.zip; mv balanced-balanced-php-* balanced; rm balanced.zip
90+
91+
And then `require` all bootstrap files:
92+
93+
<?php
94+
require(__DIR__ . "/httpful/bootstrap.php")
95+
require(__DIR__ . "/restful/bootstrap.php")
96+
require(__DIR__ . "/balanced/bootstrap.php")
97+
...
98+
99+
## Quickstart
100+
101+
curl -s http://getcomposer.org/installer | php
102+
103+
echo '{
104+
"require": {
105+
"balanced/balanced": "*"
106+
}
107+
}' > composer.json
108+
109+
php composer.phar install
110+
111+
curl https://raw.github.com/balanced/balanced-php/master/example/example.php > example.php
112+
113+
php example.php
114+
115+
curl https://raw.github.com/balanced/balanced-php/master/example/buyer-example.php > buyer-example.php
116+
117+
php -S 127.0.0.1:9321 buyer-example.php
118+
# now open a browser and go to http://127.0.0.1:9321/ to view how to tokenize cards and add to a buyer
119+
120+
## Usage
121+
122+
See https://www.balancedpayments.com/docs/overview?language=php for tutorials and documentation.
123+
124+
## Testing
125+
126+
$ phpunit --bootstrap vendor/autoload.php tests/
127+
128+
Or if you'd like to skip network calls:
129+
130+
$ phpunit --exclude-group suite --bootstrap vendor/autoload.php tests/
131+
132+
## Publishing
133+
134+
1. Ensure that **all** [tests](#testing) pass
135+
2. Increment minor `VERSION` in `src/Balanced/Settings` and `composer.json` (`git commit -am 'v{VERSION} release'`)
136+
3. Tag it (`git tag -a v{VERSION} -m 'v{VERSION} release'`)
137+
4. Push the tag (`git push --tag`)
138+
5. [Packagist](http://packagist.org/packages/balanced/balanced) will see the new tag and take it from there
139+
6. Build (`build-phar`) and upload a [phar](http://php.net/manual/en/book.phar.php) file
140+
141+
## Contributing
142+
143+
1. Fork it
144+
2. Create your feature branch (`git checkout -b my-new-feature`)
145+
3. Write your code **and [tests](#testing)**
146+
4. Ensure all tests still pass (`phpunit --bootstrap vendor/autoload.php tests/`)
147+
5. Commit your changes (`git commit -am 'Add some feature'`)
148+
6. Push to the branch (`git push origin my-new-feature`)
149+
7. Create new pull request
150+
151+
## Contributors
152+
153+
* [Jacob Rus](https://github.com/jrus)
154+
* [Leon Smith](https://github.com/leonsmith)
155+
* [Matt Drollette](https://github.com/MDrollette)
156+
* [You](https://github.com/balanced/balanced-php/issues)!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
require(__DIR__ . '/src/Balanced/Bootstrap.php');
4+
\Balanced\Bootstrap::init();

externals/balanced-php/build-phar

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/php
2+
<?php
3+
include('src/Balanced/Settings.php');
4+
5+
function exit_unless($condition, $msg = null) {
6+
if ($condition)
7+
return;
8+
echo "[FAIL] $msg";
9+
exit(1);
10+
}
11+
12+
echo "Building Phar... ";
13+
$base_dir = dirname(__FILE__);
14+
$source_dir = $base_dir . '/src/Balanced/';
15+
$phar_name = 'balanced.phar';
16+
$phar_path = $base_dir . '/' . $phar_name;
17+
$phar = new Phar($phar_path, 0, $phar_name);
18+
$stub = <<<HEREDOC
19+
<?php
20+
// Phar Stub File
21+
Phar::mapPhar('balanced.phar');
22+
include('phar://balanced.phar/Balanced/Bootstrap.php');
23+
\Balanced\Bootstrap::pharInit();
24+
25+
__HALT_COMPILER();
26+
HEREDOC;
27+
$phar->setStub($stub);
28+
exit_unless($phar, "Unable to create a phar. Make sure you have phar.readonly=0 set in your ini file.");
29+
$phar->buildFromDirectory(dirname($source_dir));
30+
echo "[ OK ]\n";
31+
32+
echo "Renaming Phar... ";
33+
$phar_versioned_name = 'balanced-' . \Balanced\Settings::VERSION . '.phar';
34+
$phar_versioned_path = $base_dir . '/' . $phar_versioned_name;
35+
rename($phar_path, $phar_versioned_path);
36+
echo "[ OK ]\n";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "balanced/balanced",
3+
"description": "Client for Balanced API",
4+
"homepage": "http://github.com/balanced/balanced-php",
5+
"license": "MIT",
6+
"keywords": ["payments", "api"],
7+
"version": "0.7.1",
8+
"authors": [
9+
{
10+
"name": "Balanced",
11+
"email": "dev@balancedpayments.com",
12+
"homepage": "http://www.balancedpayments.com"
13+
}
14+
],
15+
"require": {
16+
"nategood/httpful": "*",
17+
"bninja/restful": "*"
18+
},
19+
"autoload": {
20+
"psr-0": {
21+
"Balanced": "src/"
22+
}
23+
}
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
//
3+
// Learn how to authenticate a bank account so you can debit with it.
4+
//
5+
6+
require(__DIR__ . '/vendor/autoload.php');
7+
8+
Httpful\Bootstrap::init();
9+
RESTful\Bootstrap::init();
10+
Balanced\Bootstrap::init();
11+
12+
// create a new marketplace
13+
$key = new Balanced\APIKey();
14+
$key->save();
15+
Balanced\Settings::$api_key = $key->secret;
16+
$marketplace = new Balanced\Marketplace();
17+
$marketplace->save();
18+
19+
// create a bank account
20+
$bank_account = $marketplace->createBankAccount("Jack Q Merchant",
21+
"123123123",
22+
"123123123"
23+
);
24+
$buyer = $marketplace->createAccount("buyer@example.org");
25+
$buyer->addBankAccount($bank_account);
26+
27+
print("you can't debit from a bank account until you verify it\n");
28+
try {
29+
$buyer->debit(100);
30+
} catch (Exception $e) {
31+
printf("Debit failed, %s\n", $e->getMessage());
32+
}
33+
34+
// authenticate
35+
$verification = $bank_account->verify();
36+
37+
try {
38+
$verification->confirm(1, 2);
39+
} catch (Balanced\Errors\BankAccountVerificationFailure $e) {
40+
printf('Authentication error , %s\n', $e->getMessage());
41+
print("PROTIP: for TEST bank accounts the valid amount is always 1 and 1\n");
42+
43+
}
44+
45+
$verification->confirm(1, 1);
46+
47+
$debit = $buyer->debit(100);
48+
printf("debited the bank account %s for %d cents\n",
49+
$debit->source->uri,
50+
$debit->amount
51+
);
52+
print("and there you have it");
53+
54+
?>

0 commit comments

Comments
 (0)