-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from zaporylie/recurring
Support for Payment Recurring
- Loading branch information
Showing
40 changed files
with
2,784 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Api; | ||
|
||
use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; | ||
use zaporylie\Vipps\Resource\RecurringPayment\CancelCharge; | ||
use zaporylie\Vipps\Resource\RecurringPayment\CaptureCharge; | ||
use zaporylie\Vipps\Resource\RecurringPayment\CreateAgreement; | ||
use zaporylie\Vipps\Resource\RecurringPayment\CreateCharge; | ||
use zaporylie\Vipps\Resource\RecurringPayment\GetAgreement; | ||
use zaporylie\Vipps\Resource\RecurringPayment\GetAgreements; | ||
use zaporylie\Vipps\Resource\RecurringPayment\GetCharge; | ||
use zaporylie\Vipps\Resource\RecurringPayment\GetCharges; | ||
use zaporylie\Vipps\Resource\RecurringPayment\RefundCharge; | ||
use zaporylie\Vipps\Resource\RecurringPayment\UpdateAgreement; | ||
use zaporylie\Vipps\VippsInterface; | ||
|
||
/** | ||
* Class RecurringPayment | ||
* | ||
* @package Vipps\Api | ||
*/ | ||
class RecurringPayment extends ApiBase implements RecurringPaymentInterface | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $merchantSerialNumber; | ||
|
||
/** | ||
* Gets merchantSerialNumber value. | ||
* | ||
* @return string | ||
*/ | ||
public function getMerchantSerialNumber() | ||
{ | ||
if (empty($this->merchantSerialNumber)) { | ||
throw new InvalidArgumentException('Missing merchant serial number'); | ||
} | ||
return $this->merchantSerialNumber; | ||
} | ||
|
||
/** | ||
* Payment constructor. | ||
* | ||
* Payments API needs one extra param - merchant serial number. | ||
* | ||
* @param \zaporylie\Vipps\VippsInterface $app | ||
* @param string $subscription_key | ||
* @param $merchant_serial_number | ||
* @param $custom_path | ||
*/ | ||
public function __construct( | ||
VippsInterface $app, | ||
$subscription_key, | ||
$merchant_serial_number | ||
) { | ||
parent::__construct($app, $subscription_key); | ||
$this->merchantSerialNumber = $merchant_serial_number; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createAgreement(RequestCreateAgreement $request) | ||
{ | ||
$resource = new CreateAgreement($this->app, $this->getSubscriptionKey(), $request); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAgreements() | ||
{ | ||
$resource = new GetAgreements($this->app, $this->getSubscriptionKey()); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAgreement($agreement_id) | ||
{ | ||
$resource = new GetAgreement($this->app, $this->getSubscriptionKey(), $agreement_id); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function updateAgreement($agreement_id, RequestUpdateAgreement $request) | ||
{ | ||
$resource = new UpdateAgreement($this->app, $this->getSubscriptionKey(), $agreement_id, $request); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getCharges($agreement_id) | ||
{ | ||
$resource = new GetCharges($this->app, $this->getSubscriptionKey(), $agreement_id); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getCharge($agreement_id, $charge_id) | ||
{ | ||
$resource = new GetCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function createCharge($agreement_id, RequestCreateCharge $request) | ||
{ | ||
$resource = new CreateCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $request); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function cancelCharge($agreement_id, $charge_id) | ||
{ | ||
$resource = new CancelCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function captureCharge($agreement_id, $charge_id) | ||
{ | ||
$resource = new CaptureCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function refundCharge($agreement_id, $charge_id, RequestRefundCharge $requestObject) | ||
{ | ||
$resource = new RefundCharge( | ||
$this->app, | ||
$this->getSubscriptionKey(), | ||
$agreement_id, | ||
$charge_id, | ||
$requestObject | ||
); | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Api; | ||
|
||
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge; | ||
use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; | ||
|
||
/** | ||
* Interface PaymentInterface | ||
* | ||
* @package Vipps\Api | ||
*/ | ||
interface RecurringPaymentInterface | ||
{ | ||
|
||
/** | ||
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement | ||
* | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement | ||
*/ | ||
public function createAgreement(RequestCreateAgreement $requestCreateAgreement); | ||
|
||
/** | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[] | ||
*/ | ||
public function getAgreements(); | ||
|
||
/** | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement | ||
*/ | ||
public function getAgreement($agreement_id); | ||
|
||
/** | ||
* @param $agreement_id | ||
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement $request | ||
* | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement | ||
*/ | ||
public function updateAgreement($agreement_id, RequestUpdateAgreement $request); | ||
|
||
/** | ||
* @param $agreement_id | ||
* | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\Charge[] | ||
*/ | ||
public function getCharges($agreement_id); | ||
|
||
/** | ||
* @param $agreement_id | ||
* @param $charge_id | ||
* | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\Charge | ||
*/ | ||
public function getCharge($agreement_id, $charge_id); | ||
|
||
/** | ||
* @param $agreement_id | ||
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge $request | ||
* | ||
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateCharge | ||
*/ | ||
public function createCharge($agreement_id, RequestCreateCharge $request); | ||
|
||
/** | ||
* @param string $agreement_id | ||
* @param string $charge_id | ||
* | ||
* @return string | ||
*/ | ||
public function cancelCharge($agreement_id, $charge_id); | ||
|
||
/** | ||
* @param string $agreement_id | ||
* @param string $charge_id | ||
* | ||
* @return string | ||
*/ | ||
public function captureCharge($agreement_id, $charge_id); | ||
|
||
/** | ||
* @param string $agreement_id | ||
* @param string $charge_id | ||
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge $requestObject | ||
* | ||
* @return string | ||
*/ | ||
public function refundCharge($agreement_id, $charge_id, RequestRefundCharge $requestObject); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Api; | ||
|
||
use zaporylie\Vipps\Resource\UserInfo\UserInfo as UserInfoResource; | ||
use zaporylie\Vipps\VippsInterface; | ||
|
||
/** | ||
* Class UserInfo | ||
* | ||
* @package Vipps\Api | ||
*/ | ||
class UserInfo extends ApiBase implements UserInfoInterface | ||
{ | ||
|
||
/** | ||
* UserInfo constructor. | ||
* | ||
* @param \zaporylie\Vipps\VippsInterface $app | ||
*/ | ||
public function __construct(VippsInterface $app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function userInfo($sub) | ||
{ | ||
$resource = new UserInfoResource($this->app, $sub); | ||
/** @var \zaporylie\Vipps\Model\UserInfo\ResponseUserInfo $response */ | ||
$response = $resource->call(); | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Api; | ||
|
||
/** | ||
* Interface UserInfoInterface | ||
* | ||
* @package Vipps\Api | ||
*/ | ||
interface UserInfoInterface | ||
{ | ||
|
||
/** | ||
* @param string $sub | ||
* | ||
* @return \zaporylie\Vipps\Model\UserInfo\ResponseUserInfo | ||
*/ | ||
public function userInfo($sub); | ||
} |
Oops, something went wrong.