Skip to content

Feat/recurring v3 support #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from
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
47 changes: 27 additions & 20 deletions src/Api/RecurringPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace zaporylie\Vipps\Api;

use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException;
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement;
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase;
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge;
use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge;
use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement;
use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase;
use zaporylie\Vipps\Model\RecurringPayment\v3\RequestCaptureCharge;
use zaporylie\Vipps\Resource\RecurringPayment\CancelCharge;
use zaporylie\Vipps\Resource\RecurringPayment\CaptureCharge;
use zaporylie\Vipps\Resource\RecurringPayment\CreateAgreement;
Expand All @@ -32,6 +33,11 @@ class RecurringPayment extends ApiBase implements RecurringPaymentInterface
*/
protected $merchantSerialNumber;

/**
* @var int
*/
protected $api_endpoint_version;

/**
* Gets merchantSerialNumber value.
*
Expand All @@ -46,30 +52,30 @@ public function getMerchantSerialNumber()
}

/**
* Payment constructor.
*
* Payments API needs one extra param - merchant serial number.
* Recurring Payments constructor.
*
* @param \zaporylie\Vipps\VippsInterface $app
* @param string $subscription_key
* @param $merchant_serial_number
* @param $custom_path
* @param int $api_endpoint_version
*/
public function __construct(
VippsInterface $app,
$subscription_key,
$merchant_serial_number
$merchant_serial_number,
$api_endpoint_version
) {
parent::__construct($app, $subscription_key);
$this->merchantSerialNumber = $merchant_serial_number;
$this->api_endpoint_version = $api_endpoint_version;
}

/**
* {@inheritdoc}
*/
public function createAgreement(RequestCreateAgreement $request)
public function createAgreement(RequestCreateAgreementBase $request)
{
$resource = new CreateAgreement($this->app, $this->getSubscriptionKey(), $request);
$resource = new CreateAgreement($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $request);
$response = $resource->call();
return $response;
}
Expand All @@ -79,7 +85,7 @@ public function createAgreement(RequestCreateAgreement $request)
*/
public function getAgreements()
{
$resource = new GetAgreements($this->app, $this->getSubscriptionKey());
$resource = new GetAgreements($this->app, $this->api_endpoint_version, $this->getSubscriptionKey());
$response = $resource->call();
return $response;
}
Expand All @@ -89,17 +95,17 @@ public function getAgreements()
*/
public function getAgreement($agreement_id)
{
$resource = new GetAgreement($this->app, $this->getSubscriptionKey(), $agreement_id);
$resource = new GetAgreement($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id);
$response = $resource->call();
return $response;
}

/**
* {@inheritdoc}
*/
public function updateAgreement($agreement_id, RequestUpdateAgreement $request)
public function updateAgreement($agreement_id, RequestUpdateAgreementBase $request)
{
$resource = new UpdateAgreement($this->app, $this->getSubscriptionKey(), $agreement_id, $request);
$resource = new UpdateAgreement($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $request);
$response = $resource->call();
return $response;
}
Expand All @@ -109,7 +115,7 @@ public function updateAgreement($agreement_id, RequestUpdateAgreement $request)
*/
public function getCharges($agreement_id)
{
$resource = new GetCharges($this->app, $this->getSubscriptionKey(), $agreement_id);
$resource = new GetCharges($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id);
$response = $resource->call();
return $response;
}
Expand All @@ -119,7 +125,7 @@ public function getCharges($agreement_id)
*/
public function getCharge($agreement_id, $charge_id)
{
$resource = new GetCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id);
$resource = new GetCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id);
$response = $resource->call();
return $response;
}
Expand All @@ -129,7 +135,7 @@ public function getCharge($agreement_id, $charge_id)
*/
public function createCharge($agreement_id, RequestCreateCharge $request)
{
$resource = new CreateCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $request);
$resource = new CreateCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $request);
$response = $resource->call();
return $response;
}
Expand All @@ -139,17 +145,17 @@ public function createCharge($agreement_id, RequestCreateCharge $request)
*/
public function cancelCharge($agreement_id, $charge_id)
{
$resource = new CancelCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id);
$resource = new CancelCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id);
$response = $resource->call();
return $response;
}

/**
* {@inheritDoc}
*/
public function captureCharge($agreement_id, $charge_id)
public function captureCharge($agreement_id, $charge_id, RequestCaptureCharge $requestObject)
{
$resource = new CaptureCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id);
$resource = new CaptureCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id, $requestObject);
$response = $resource->call();
return $response;
}
Expand All @@ -160,7 +166,8 @@ public function captureCharge($agreement_id, $charge_id)
public function refundCharge($agreement_id, $charge_id, RequestRefundCharge $requestObject)
{
$resource = new RefundCharge(
$this->app,
$this->app,
$this->api_endpoint_version,
$this->getSubscriptionKey(),
$agreement_id,
$charge_id,
Expand Down
19 changes: 10 additions & 9 deletions src/Api/RecurringPaymentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace zaporylie\Vipps\Api;

use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement;
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase;
use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge;
use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge;
use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement;
use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase;
use zaporylie\Vipps\Model\RecurringPayment\v3\RequestCaptureCharge;

/**
* Interface PaymentInterface
Expand All @@ -16,29 +17,29 @@ interface RecurringPaymentInterface
{

/**
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase
*
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement
*/
public function createAgreement(RequestCreateAgreement $requestCreateAgreement);
public function createAgreement(RequestCreateAgreementBase $requestCreateAgreement);

/**
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[]
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase[]
*/
public function getAgreements();

/**
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase
*/
public function getAgreement($agreement_id);

/**
* @param $agreement_id
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement $request
* @param \zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase $request
*
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement
*/
public function updateAgreement($agreement_id, RequestUpdateAgreement $request);
public function updateAgreement($agreement_id, RequestUpdateAgreementBase $request);

/**
* @param $agreement_id
Expand Down Expand Up @@ -77,7 +78,7 @@ public function cancelCharge($agreement_id, $charge_id);
*
* @return string
*/
public function captureCharge($agreement_id, $charge_id);
public function captureCharge($agreement_id, $charge_id, RequestCaptureCharge $requestObject);

/**
* @param string $agreement_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,18 @@
use JMS\Serializer\Annotation as Serializer;

/**
* Class ResponseGetAgreement
* Class AgreementBase
*
* @package Vipps\Model\RecurringPayment
*/
class Agreement
class AgreementBase
{

/**
* @var \zaporylie\Vipps\Model\RecurringPayment\CampaignRequest
* @Serializer\Type("zaporylie\Vipps\Model\RecurringPayment\CampaignRequest")
*/
protected $campaign;

/**
* @var string
* @Serializer\Type("string")
*/
protected $currency;

/**
* @var string
* @Serializer\Type("string")
*/
protected $id;

/**
* @var string
* @Serializer\Type("string")
*/
protected $interval;

/**
* @var int
* @Serializer\Type("integer")
*/
protected $intervalCount;

/**
* @var int
* @Serializer\Type("integer")
*/
protected $price;

/**
* @var string
* @Serializer\Type("string")
Expand Down Expand Up @@ -96,26 +65,6 @@ class Agreement
*/
protected $tags;

/**
* Gets campaign value.
*
* @return \zaporylie\Vipps\Model\RecurringPayment\CampaignRequest
*/
public function getCampaign()
{
return $this->campaign;
}

/**
* Gets currency value.
*
* @return string
*/
public function getCurrency()
{
return $this->currency;
}

/**
* Gets id value.
*
Expand All @@ -126,36 +75,6 @@ public function getId()
return $this->id;
}

/**
* Gets interval value.
*
* @return string
*/
public function getInterval()
{
return $this->interval;
}

/**
* Gets intervalCount value.
*
* @return int
*/
public function getIntervalCount()
{
return $this->intervalCount;
}

/**
* Gets price value.
*
* @return int
*/
public function getPrice()
{
return $this->price;
}

/**
* Gets productDescription value.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Model/RecurringPayment/RequestCreateAgreementBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace zaporylie\Vipps\Model\RecurringPayment;

/**
* Class RequestCreateAgreementBase
*
* @package Vipps\Model\RecurringPayment
*/
class RequestCreateAgreementBase
{

}
22 changes: 21 additions & 1 deletion src/Model/RecurringPayment/RequestCreateCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use JMS\Serializer\Annotation as Serializer;

/**
* Class ResponseGetAgreement
* Class RequestCreateCharge
*
* @package Vipps\Model\RecurringPayment
*/
Expand Down Expand Up @@ -47,6 +47,12 @@ class RequestCreateCharge
*/
protected $orderId;

/**
* @var string
* @Serializer\Type("string")
*/
protected $transactionType;

/**
* Sets amount variable.
*
Expand Down Expand Up @@ -124,4 +130,18 @@ public function setOrderId($orderId)
$this->orderId = $orderId;
return $this;
}

/**
* Set the value of transactionType
*
* @param string $transactionType
*
* @return self
*/
public function setTransactionType(string $transactionType)
{
$this->transactionType = $transactionType;

return $this;
}
}
13 changes: 13 additions & 0 deletions src/Model/RecurringPayment/RequestUpdateAgreementBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace zaporylie\Vipps\Model\RecurringPayment;

/**
* Class RequestUpdateAgreementBase
*
* @package Vipps\Model\RecurringPayment
*/
class RequestUpdateAgreementBase
{

}
Loading