Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Crosspay",
"name": "gurimmer/Crosspay",
"description": "Crosspay is an online payment API wrapper.",
"type": "library",
"require": {
"php": "^7.0",
Expand All @@ -16,7 +17,7 @@
"authors": [
{
"name": "gorou178",
"email": "s.anai@innovator.jp.net"
"email": "s.reianai@gmail.com"
}
],
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -17,7 +17,7 @@
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
3 changes: 2 additions & 1 deletion src/crosspay/ChargeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Crosspay;

use Crosspay\response\Charge;
use Crosspay\response\Collection;
use Crosspay\response\Refund;

interface ChargeInterface
Expand All @@ -15,7 +16,7 @@ public function save(Charge $target, $params = null, $options = null) : Charge;

public function capture(Charge $target, $params = null, $options = null) : Charge;

public function all($params = null, $options = null) : array;
public function all($params = null, $options = null) : Collection;

public function refund(Charge $target, $params = null, $options = null) : Refund;
}
3 changes: 2 additions & 1 deletion src/crosspay/CustomerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crosspay;

use Crosspay\response\Collection;
use Crosspay\response\Customer;

interface CustomerInterface
Expand All @@ -14,5 +15,5 @@ public function delete(Customer $target, $params = null, $options = null) : Cust

public function retrieve($id, $options = null) : Customer;

public function all($params = null, $options = null) : array;
public function all($params = null, $options = null) : Collection;
}
3 changes: 2 additions & 1 deletion src/crosspay/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Crosspay;

use Crosspay\response\Collection;
use Crosspay\response\Event;

interface EventInterface
{
public function retrieve($id, $options = null) : Event;
public function all($params = null, $options = null) : array;
public function all($params = null, $options = null) : Collection;
}
3 changes: 2 additions & 1 deletion src/crosspay/SubscriptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crosspay;

use Crosspay\response\Collection;
use Crosspay\response\Subscription;

interface SubscriptionInterface
Expand All @@ -14,5 +15,5 @@ public function retrieve($id, $params = null, $options = null) : Subscription;

public function cancel(Subscription $target, $params = null, $options = null) : Subscription;

public function all($params = null, $options = null) : array;
public function all($params = null, $options = null) : Collection;
}
3 changes: 2 additions & 1 deletion src/crosspay/adapter/NullCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Crosspay\Adapter;

use Crosspay\response\Charge;
use Crosspay\response\Collection;
use Crosspay\response\Refund;

class NullCharge extends AbstractCharge
Expand All @@ -28,7 +29,7 @@ public function capture(Charge $target, $params = null, $options = null): Charge
return null;
}

public function all($params = null, $options = null): array
public function all($params = null, $options = null): Collection
{
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/crosspay/adapter/NullCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crosspay\Adapter;

use Crosspay\response\Collection;
use Crosspay\response\Customer;

class NullCustomer extends AbstractCustomer
Expand All @@ -27,7 +28,7 @@ public function retrieve($id, $options = null): Customer
return null;
}

public function all($params = null, $options = null): array
public function all($params = null, $options = null): Collection
{
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/crosspay/adapter/NullEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crosspay\Adapter;

use Crosspay\response\Collection;
use Crosspay\response\Event;

class NullEvent extends AbstractEvent
Expand All @@ -11,7 +12,7 @@ public function retrieve($id, $params = null, $options = null) : Event
return null;
}

public function all($params = null, $options = null) : array
public function all($params = null, $options = null) : Collection
{
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/crosspay/adapter/NullSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crosspay\Adapter;

use Crosspay\response\Collection;
use Crosspay\response\Subscription;

class NullSubscription extends AbstractSubscription
Expand All @@ -27,7 +28,7 @@ public function cancel(Subscription $target, $params = null, $options = null) :
return null;
}

public function all($params = null, $options = null) : array
public function all($params = null, $options = null) : Collection
{
return null;
}
Expand Down
10 changes: 3 additions & 7 deletions src/crosspay/payjp/PayjpCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Crosspay\Adapter\AbstractCharge;
use Crosspay\exception\CrosspayException;
use Crosspay\response\Charge;
use Crosspay\response\Collection;
use Crosspay\response\Refund;
use Exception;

Expand Down Expand Up @@ -68,19 +69,14 @@ public function capture(Charge $target, $params = null, $options = null): Charge
}
}

public function all($params = null, $options = null): array
public function all($params = null, $options = null): Collection
{
try {
$charges = \Payjp\Charge::all($params, $options);
return new PayjpCollectionResponse($charges);
} catch (Exception $e) {
throw new CrosspayException('charge all exception from payjp', 0, $e);
}

$results = [];
foreach ($charges as $charge) {
$results[] = new PayjpChargeResponse($charge);
}
return $results;
}

public function refund(Charge $target, $params = null, $options = null): Refund
Expand Down
59 changes: 59 additions & 0 deletions src/crosspay/payjp/PayjpCollectionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Crosspay\payjp;

use Crosspay\response\Collection;

class PayjpCollectionResponse extends Collection
{

protected function convertData() : array
{
$url = $this->url();
$responseClass = '';
if (strpos($url, 'charges') !== false) {
$responseClass = 'PayjpChargeResponse';
}
if (strpos($url, 'subscriptions') !== false) {
$responseClass = 'PayjpSubscriptionResponse';
}
if (strpos($url, 'customers') !== false) {
$responseClass = 'PayjpCustomerResponse';
}
if (strpos($url, 'events') !== false) {
$responseClass = 'PayjpEventResponse';
}

$results = [];
foreach ($this->response->data as $data) {
$results[] = new $responseClass($data);
}
return $results;
}

public function __construct(string $response = '')
{
parent::__construct($response);

}

public function count(): int
{
return $this->response->count;
}

public function url(): string
{
return $this->response->url;
}

public function hasMore(): bool
{
return $this->response->has_more;
}

public function data(): array
{
return $this->convertData();
}
}
10 changes: 3 additions & 7 deletions src/crosspay/payjp/PayjpCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Crosspay\Adapter\AbstractCustomer;
use Crosspay\exception\CrosspayException;
use Crosspay\response\Collection;
use Crosspay\response\Customer;
use Exception;

Expand Down Expand Up @@ -67,18 +68,13 @@ public function retrieve($id, $options = null): Customer
}
}

public function all($params = null, $options = null): array
public function all($params = null, $options = null): Collection
{
try {
$customers = \Payjp\Customer::all($params, $options);
return new PayjpCollectionResponse($customers);
} catch (Exception $e) {
throw new CrosspayException('customer all exception from payjp', 0, $e);
}

$results = [];
foreach ($customers as $customer) {
$results[] = new PayjpCustomerResponse($customer);
}
return $results;
}
}
10 changes: 3 additions & 7 deletions src/crosspay/payjp/PayjpEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Crosspay\Adapter\AbstractEvent;
use Crosspay\exception\CrosspayException;
use Crosspay\response\Collection;
use Crosspay\response\Event;
use Exception;

Expand All @@ -20,18 +21,13 @@ public function retrieve($id, $options = null): Event
}
}

public function all($params = null, $options = null): array
public function all($params = null, $options = null): Collection
{
try {
$events = \Payjp\Event::all($params, $options);
return new PayjpCollectionResponse($events);
} catch (Exception $e) {
throw new CrosspayException('event all exception from payjp', 0, $e);
}

$results = [];
foreach ($events as $event) {
$results[] = new PayjpEventResponse($event);
}
return $results;
}
}
10 changes: 3 additions & 7 deletions src/crosspay/payjp/PayjpSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Crosspay\Adapter\AbstractSubscription;
use Crosspay\exception\CrosspayException;
use Crosspay\response\Collection;
use Crosspay\response\Subscription;
use Exception;

Expand Down Expand Up @@ -67,18 +68,13 @@ public function cancel(Subscription $target, $params = null, $options = null): S
}
}

public function all($params = null, $options = null): array
public function all($params = null, $options = null): Collection
{
try {
$subscriptions = \Payjp\Subscription::all($params, $options);
return new PayjpCollectionResponse($subscriptions);
} catch (Exception $e) {
throw new CrosspayException('subscription all exception from payjp', 0, $e);
}

$results = [];
foreach ($subscriptions as $subscription) {
$results[] = new PayjpSubscriptionResponse($subscription);
}
return $results;
}
}
12 changes: 12 additions & 0 deletions src/crosspay/response/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Crosspay\response;

abstract class Collection extends ResponseBase
{
abstract protected function convertData() : array;
abstract public function count() : int;
abstract public function url() : string;
abstract public function hasMore() : bool;
abstract public function data() : array;
}
10 changes: 3 additions & 7 deletions src/crosspay/stripe/StripeCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Crosspay\Adapter\AbstractCharge;
use Crosspay\exception\CrosspayException;
use Crosspay\response\Charge;
use Crosspay\response\Collection;
use Crosspay\response\Refund;
use Exception;

Expand Down Expand Up @@ -68,19 +69,14 @@ public function capture(Charge $target, $params = null, $options = null) : Charg
}
}

public function all($params = null, $options = null) : array
public function all($params = null, $options = null) : Collection
{
try {
$charges = \Stripe\Charge::all($params, $options);
return new StripeCollectionResponse($charges);
} catch (Exception $e) {
throw new CrosspayException('charge all exception from stripe', 0, $e);
}

$results = [];
foreach ($charges as $charge) {
$results[] = new StripeChargeResponse($charge);
}
return $results;
}

public function refund(Charge $target, $params = null, $options = null) : Refund
Expand Down
Loading