Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
include indo cc endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
seowyanyi committed Mar 30, 2017
1 parent 448395e commit 62667f5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
52 changes: 52 additions & 0 deletions examples/CardsTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
<?php

require_once('../init.php');
// INDO
\Xfers\Xfers::setIDSandbox();

try {
echo "Charge guest card\n";
$chargeId = '670ee7406c424968ac5587852743ebd1'; // you must create a charge first
$params = array(
'txn_id' => $chargeId,
'card_name' => 'Visnu',
'card_type' => 'V',
'card_no' => '4137180300023783',
'card_cvc' => '666',
'expiry_month' => '01',
'expiry_year' => '2021',
'save_card' => true
);
$resp = \Xfers\Card::chargeGuest($params);
print_r($resp);
} catch (\Xfers\Error\InvalidRequest $e) {
echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n";
}

try {
\Xfers\Xfers::setApiKey('LXcbEXxAZ894yVsSC1-iLpUWFx_RKTgeASsdL5TZhbc');
echo "Listing all cards\n";
$customer = "hello@xfers.io";
$resp = \Xfers\Card::listAll($customer);
print_r($resp);
} catch (\Xfers\Error\InvalidRequest $e) {
echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n";
}

try {
echo "Charge existing card\n";
$chargeId = '5d8c605550114d3fbfdeffbf85ba3d69';
$token = '2D23113F-307F-41CA-8921-7A977668E3EC';
$resp = \Xfers\Card::chargeExisting($chargeId, $token);
print_r($resp);
} catch (\Xfers\Error\InvalidRequest $e) {
echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n";
}

try {
echo "Deleting card\n";
$token = '2D23113F-307F-41CA-8921-7A977668E3EC';
$resp = \Xfers\Card::delete($token);
print_r($resp);
} catch (\Xfers\Error\InvalidRequest $e) {
echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n";
}


// SINGAPORE
\Xfers\Xfers::setApiKey('WuTp3zM7UEpmUkeAyGPxRHmnXAx-hXJ7jzdqmxY6S1o');
\Xfers\Xfers::setSGSandbox();

Expand Down
8 changes: 0 additions & 8 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ private function _requestRaw($method, $url, $params, $headers, $connectKey = nul
$myApiKey = Xfers::$apiKey;
}

if (!$myApiKey) {
$msg = 'No API key provided. (HINT: set your API key using '
. '"Xfers::setApiKey(<API-KEY>)". You can generate API keys from '
. 'the Xfers web interface. See http://docs.xfers.io/#authentication for '
. 'details, or email support@xfers.io if you have any questions.';
throw new Error\Authentication($msg);
}

$absUrl = $this->_apiBase.$url;

$langVersion = phpversion();
Expand Down
37 changes: 26 additions & 11 deletions lib/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ class Card extends ApiResource
{
public static $baseUrl = '/cards';

public static function listAll($userApiToken)
public static function listAll($param)
{
$url = self::$baseUrl . "?user_api_token=" . $userApiToken;
return self::_get($url, null);
if (strpos(Xfers::$apiBase, 'id') !== false) {
$url = self::$baseUrl . "?customer=" . $param;
return self::_get($url, null);
} else {
$url = self::$baseUrl . "?user_api_token=" . $param;
return self::_get($url, null);
}
}

public static function add($params)
{
return self::_post($params, self::$baseUrl, null);
}

public static function delete($id, $userApiToken)
public static function delete($id, $userApiToken=null)
{
$url = self::$baseUrl . "/" . $id;
$params = array(
'user_api_token' => $userApiToken
);
$params = null;
if ($userApiToken != null) {
$params = array(
'user_api_token' => $userApiToken
);
}
return self::_delete($url, null, $params);
}

Expand All @@ -41,12 +49,19 @@ public static function chargeGuest($params)
return self::_post($params, $url, null);
}

public static function chargeExisting($chargeId)
public static function chargeExisting($chargeId, $token=null)
{
$url = "/credit_card_charges/charge_card";
$params = array(
'txn_id' => $chargeId
);
if ($token != null) {
$params = array(
'txn_id' => $chargeId,
'token' => $token
);
} else {
$params = array(
'txn_id' => $chargeId
);
}
return self::_post($params, $url, null);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Xfers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Xfers
const IDproductionBase = 'https://id.xfers.com/api/v3';

public static $apiBase = "";
const VERSION = '1.2.0';
const VERSION = '1.3.0';

/**
* @return string The API key used for requests.
Expand Down

0 comments on commit 62667f5

Please sign in to comment.