1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00
phorge-phorge/externals/wepay/demoapp/login.php
epriestley 49ef13e876 Add WePay as a one-time payment provider
Summary:
Ref T2787.

I //think// we could also use WePay as a recurring payment provider, but this is somewhat messy (OAuth + requires account) -- basically it's "add a WePay account" instead of "add a credit card".

The WePay checkout workflow is a bit upsell-y but basically reasonable.

I like that their API just has a `request($method, $params)` method instead of 30,000 lines of methods for each request type. I did hit one bug; I'll send a pull for that.

Test Plan: Got as far as the charge callback in testing; the rest isn't implemented for any provider yet.

Reviewers: btrahan, vrana, chad

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D5982
2013-05-21 15:34:46 -07:00

41 lines
1.2 KiB
PHP

<?php
require './_shared.php';
// ** YOU MUST CHANGE THIS FOR THE SAMPLE APP TO WORK **
$redirect_uri = 'http://YOUR SERVER NAME/login.php';
$scope = WePay::getAllScopes();
// If we are already logged in, send the user home
if (!empty($_SESSION['wepay_access_token'])) {
header('Location: index.php');
exit;
}
// If the authentication dance returned an error, catch it to avoid a
// redirect loop. This usually indicates some sort of application issue,
// like a domain mismatch on your redirect_uri
if (!empty($_GET['error'])) {
echo 'Error during user authentication: ';
echo htmlentities($_GET['error_description']);
exit;
}
// If we don't have a code from being redirected back here,
// send the user to WePay to grant permissions.
if (empty($_GET['code'])) {
$uri = WePay::getAuthorizationUri($scope, $redirect_uri);
header("Location: $uri");
}
else {
$info = WePay::getToken($_GET['code'], $redirect_uri);
if ($info) {
// Normally you'd integrate this into your existing auth system
$_SESSION['wepay_access_token'] = $info->access_token;
// If desired, you can also store $info->user_id somewhere
header('Location: index.php');
}
else {
// Unable to obtain access token
echo 'Unable to obtain access token from WePay.';
}
}