Skip to content

Commit

Permalink
Merge pull request #4 from SincosSoftware/feature/update-recurring-ap…
Browse files Browse the repository at this point in the history
…i-to-v3

Use Vipps Recurring V3 API
  • Loading branch information
rogerlysberg authored Apr 18, 2024
2 parents fc6939f + 751b96e commit 82b3b98
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Model/Agreement/RequestChargeAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class RequestChargeAgreement
{
protected $amount = 0;
protected $currency = 'NOK';
protected $description;
protected $due;
protected $retryDays = 7;
protected $transactionType = 'DIRECT_CAPTURE';

public function __construct($amount, $description)
{
Expand Down
23 changes: 14 additions & 9 deletions src/Model/Agreement/RequestInitiateAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@
*/
class RequestInitiateAgreement
{
protected $currency = 'NOK';

protected $customerPhoneNumber;
protected $phoneNumber;
protected $interval;
protected $intervalCount;
protected $isApp = false;

protected $merchantRedirectUrl;
protected $merchantAgreementUrl;
protected $price;
protected $productDescription;
protected $productName;
protected $pricing;
//protected $scope = "address birthDate email name phoneNumber";

public function __construct($phoneNumber, $price, $productName, $productDescription, $interval, $intervalCount, $redirectUrl, $agreementUrl)
{
$this->customerPhoneNumber = $phoneNumber;
$this->price = $price;
$this->phoneNumber = $phoneNumber;
$this->productName = $productName;
$this->productDescription = $productDescription;
$this->interval = $interval;
$this->intervalCount = $intervalCount;
$this->merchantRedirectUrl = $redirectUrl;
$this->merchantAgreementUrl = $agreementUrl;

$this->pricing = [
'type' => 'LEGACY',
'amount' => $price,
'currency' => 'NOK'
];

$this->interval = [
'unit' => $interval,
'count' => $intervalCount
];
}
}
10 changes: 5 additions & 5 deletions src/Model/Agreement/ResponseGetAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class ResponseGetAgreement
protected $productName;

/**
* @var string
* @Serializer\Type("string")
* @var array
* @Serializer\Type("array")
*/
protected $price;
protected $pricing;

/**
* @var string
Expand All @@ -55,8 +55,8 @@ class ResponseGetAgreement
protected $productDescription;

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

Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Agreement/ChargeAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ChargeAgreement extends AgreementResourceBase
/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}/charges';
protected $path = '/recurring/v3/agreements/{id}/charges';

/**
* InitiatePayment constructor.
Expand Down
4 changes: 2 additions & 2 deletions src/Resource/Agreement/ContinueAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class ContinueAgreement extends PaymentResourceBase
/**
* @var \SincosSoftware\Vipps\Resource\HttpMethod
*/
protected $method = HttpMethod::PUT;
protected $method = HttpMethod::PATCH;

/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}';
protected $path = '/recurring/v3/agreements/{id}';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Agreement/GetAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GetAgreement extends PaymentResourceBase
/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}';
protected $path = '/recurring/v3/agreements/{id}';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Agreement/GetAllAgreements.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GetAllAgreements extends PaymentResourceBase
/**
* @var string
*/
protected $path = '/recurring/v2/agreements';
protected $path = '/recurring/v3/agreements';

/**
* InitiatePayment constructor.
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Agreement/GetChargeStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetChargeStatus extends AgreementResourceBase
/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}/charges/{id2}';
protected $path = '/recurring/v3/agreements/{id}/charges/{id2}';

public function __construct(VippsInterface $vipps, $subscription_key, $agreement_id, $charge_id)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Agreement/InitiateAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InitiateAgreement extends AgreementResourceBase
/**
* @var string
*/
protected $path = '/recurring/v2/agreements';
protected $path = '/recurring/v3/agreements';

/**
* InitiatePayment constructor.
Expand Down
4 changes: 2 additions & 2 deletions src/Resource/Agreement/PauseAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class PauseAgreement extends PaymentResourceBase
/**
* @var \SincosSoftware\Vipps\Resource\HttpMethod
*/
protected $method = HttpMethod::PUT;
protected $method = HttpMethod::PATCH;

/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}';
protected $path = '/recurring/v3/agreements/{id}';


/**
Expand Down
8 changes: 6 additions & 2 deletions src/Resource/Agreement/RefundCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RefundCharge extends AgreementResourceBase
/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}/charges/{id2}/refund';
protected $path = '/recurring/v3/agreements/{id}/charges/{id2}/refund';

/**
* InitiatePayment constructor.
Expand Down Expand Up @@ -50,7 +50,11 @@ public function call()
{
$response = $this->makeCall();

if ($response->getStatusCode() == 200) {
/*
* 204 No Content indicates that the request was successfully processed.
* 202 Accepted indicates that the request was accepted for processing, but the processing has not been completed.
* */
if ($response->getStatusCode() == 204 || $response->getStatusCode() == 202) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Resource/Agreement/StopAgreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class StopAgreement extends PaymentResourceBase
/**
* @var \SincosSoftware\Vipps\Resource\HttpMethod
*/
protected $method = HttpMethod::PUT;
protected $method = HttpMethod::PATCH;

/**
* @var string
*/
protected $path = '/recurring/v2/agreements/{id}';
protected $path = '/recurring/v3/agreements/{id}';


/**
Expand Down
1 change: 1 addition & 0 deletions src/Resource/HttpMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ class HttpMethod extends AbstractEnumeration
const POST = 'POST';
const PUT = 'PUT';
const DELETE = 'DELETE';
const PATCH = 'PATCH';
}

0 comments on commit 82b3b98

Please sign in to comment.