Skip to content

Commit

Permalink
Fix resource declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
zaporylie committed Jul 30, 2024
1 parent 94f8a58 commit 4a492f3
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 277 deletions.
4 changes: 2 additions & 2 deletions examples/authorization/01-token.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$result = $authorization->getToken($settings['client_secret']);
echo '<pre>';
var_dump($result);
Expand Down
6 changes: 3 additions & 3 deletions examples/checkout/01-checkout-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$checkout = new \zaporylie\Vipps\Api\v3\Checkout($client, $settings['subscription_key'], $settings['merchant_serial_number'], $settings['client_secret']);
$checkout = new \zaporylie\Vipps\Api\v3\Checkout($client);
$request = new \zaporylie\Vipps\Model\Checkout\v3\CreateCheckoutSessionRequest();
$request->setType('PAYMENT');
$request->setMerchantInfo((new \zaporylie\Vipps\Model\Checkout\v3\MerchantInfo())
Expand Down
6 changes: 3 additions & 3 deletions examples/payment/01-epayment-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client);
$result = $payment->createPayment((new \zaporylie\Vipps\Model\EPayment\v1\CreatePaymentRequest())
->setAmount((new \zaporylie\Vipps\Model\EPayment\v1\Amount())->setValue(1000)->setCurrency('NOK'))
->setPaymentMethod((new \zaporylie\Vipps\Model\EPayment\v1\PaymentMethod())->setType('WALLET'))
Expand Down
6 changes: 3 additions & 3 deletions examples/payment/02-epayment-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client);
$result = $payment->getPayment('test-12121212-4');
echo '<pre>';
var_dump($result);
Expand Down
6 changes: 3 additions & 3 deletions examples/payment/03-epayment-adjust-cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client);
$result = $payment->cancelPayment('test-12121212-3', new \zaporylie\Vipps\Model\EPayment\v1\CancelModificationRequest(), 'costam');
echo '<pre>';
var_dump($result);
Expand Down
6 changes: 3 additions & 3 deletions examples/payment/04-epayment-adjust-modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client);
$result = $payment->capturePayment('test-12121212-3', (new \zaporylie\Vipps\Model\EPayment\v1\CaptureModificationRequest())->setModificationAmount((new \zaporylie\Vipps\Model\EPayment\v1\Amount())->setCurrency('NOK')->setValue(101)), 'costam3');
echo '<pre>';
var_dump($result);
Expand Down
6 changes: 3 additions & 3 deletions examples/recurring_payment/01-recurring-payment-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client);
$result = $payment->createAgreement((new \zaporylie\Vipps\Model\RecurringPayment\v3\RequestCreateAgreement())
->setPricing((new \zaporylie\Vipps\Model\RecurringPayment\v3\Pricing())
->setCurrency('NOK')
Expand Down
6 changes: 3 additions & 3 deletions examples/recurring_payment/01-recurring-payment-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client);
$result = $payment->getAgreement('agr_KG6k3X3');
echo '<pre>';
var_dump($result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client);
$result = $payment->createCharge('agr_KG6k3X3', (new \zaporylie\Vipps\Model\RecurringPayment\v3\RequestCreateCharge())
->setAmount(1000)
->setDescription('Ok, that worked')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client);
$result = $payment->getCharge('agr_KG6k3X3','chr-gTHPbNE');
echo '<pre>';
var_dump($result);
Expand Down
6 changes: 3 additions & 3 deletions examples/webhook/01-webhook-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client);
$result = $payment->getWebhooks();
echo '<pre>';
var_dump($result);
Expand Down
6 changes: 3 additions & 3 deletions examples/webhook/02-webhook-register.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client);
$request = new \zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookRequest();
$request->setUrl("https://eoncxehuh2o2qyq.m.pipedream.net/");
$request->setEvents([
Expand Down
6 changes: 3 additions & 3 deletions examples/webhook/03-webhook-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$vipps = new \zaporylie\Vipps\Vipps($client);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);

$authorization = new \zaporylie\Vipps\Api\Authorization($client);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client);
$payment->deleteWebhook('1aaf0fde-afed-43c0-9af3-b876bba34e48');
echo 'ok';

Expand Down
27 changes: 0 additions & 27 deletions src/Api/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace zaporylie\Vipps\Api;

use zaporylie\Vipps\ClientInterface;
use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException;

abstract class ApiBase
{
Expand All @@ -22,30 +21,4 @@ public function __construct(ClientInterface $client)
{
$this->client = $client;
}

/**
* Gets subscription_key value.
*
* @return string
*/
public function getSubscriptionKey()
{
if (empty($this->subscriptionKey)) {
throw new InvalidArgumentException('Missing subscription key');
}
return $this->subscriptionKey;
}

/**
* Sets subscription_key variable.
*
* @param string $subscriptionKey
*
* @return $this
*/
public function setSubscriptionKey($subscriptionKey)
{
$this->subscriptionKey = $subscriptionKey;
return $this;
}
}
6 changes: 3 additions & 3 deletions src/Api/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace zaporylie\Vipps\Api;

use zaporylie\Vipps\Model\Authorization\ResponseGetToken;
use zaporylie\Vipps\Resource\Authorization\GetToken;

class Authorization extends ApiBase implements AuthorizationInterface
Expand All @@ -12,10 +13,9 @@ class Authorization extends ApiBase implements AuthorizationInterface
*
* @return \zaporylie\Vipps\Model\Authorization\ResponseGetToken
*/
public function getToken($client_secret)
{
public function getToken(): ResponseGetToken {
// Initiate GetToken resource.
$resource = new GetToken($this->client, $client_secret);
$resource = new GetToken($this->client);

/** @var \zaporylie\Vipps\Model\Authorization\ResponseGetToken $response */
$response = $resource->call();
Expand Down
6 changes: 3 additions & 3 deletions src/Api/AuthorizationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace zaporylie\Vipps\Api;

use zaporylie\Vipps\Model\Authorization\ResponseGetToken;

interface AuthorizationInterface
{

/**
* @param string $client_secret
*
* @return \zaporylie\Vipps\Model\Authorization\ResponseGetToken
*/
public function getToken($client_secret);
public function getToken(): ResponseGetToken;
}
10 changes: 0 additions & 10 deletions src/Api/UserInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
class UserInfo extends ApiBase implements UserInfoInterface
{

/**
* UserInfo constructor.
*
* @param \zaporylie\Vipps\ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
$this->client = $client;
}

/**
* {@inheritdoc}
*/
Expand Down
50 changes: 0 additions & 50 deletions src/Api/v1/EPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,6 @@
class EPayment extends ApiBase implements EPaymentInterface
{

/**
* @var string
*/
protected $merchantSerialNumber;

/**
* @var string
*/
protected $version;

/**
* Gets merchantSerialNumber value.
*
* @return string
*/
public function getMerchantSerialNumber()
{
if (empty($this->merchantSerialNumber)) {
throw new InvalidArgumentException('Missing merchant serial number');
}
return $this->merchantSerialNumber;
}

/**
* @return string
*/
public function getVersion()
{
return $this->version;
}

/**
* Payment constructor.
*
* Payments API needs one extra param - merchant serial number.
*
* @param \zaporylie\Vipps\ClientInterface $client
* @param string $subscription_key
* @param $merchant_serial_number
*/
public function __construct(
ClientInterface $client,
$subscription_key,
$merchant_serial_number
) {
parent::__construct($client, $subscription_key);
$this->merchantSerialNumber = $merchant_serial_number;
$this->version = 'v1';
}

/**
* {@inheritDoc}
*/
Expand Down
50 changes: 0 additions & 50 deletions src/Api/v1/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,6 @@
class Webhook extends ApiBase implements WebhookInterface
{

/**
* @var string
*/
protected $merchantSerialNumber;

/**
* @var string
*/
protected $version;

/**
* Gets merchantSerialNumber value.
*
* @return string
*/
public function getMerchantSerialNumber()
{
if (empty($this->merchantSerialNumber)) {
throw new InvalidArgumentException('Missing merchant serial number');
}
return $this->merchantSerialNumber;
}

/**
* @return string
*/
public function getVersion()
{
return $this->version;
}

/**
* Webhook constructor.
*
* Webhook API needs one extra param - merchant serial number.
*
* @param \zaporylie\Vipps\ClientInterface $client
* @param string $subscription_key
* @param $merchant_serial_number
*/
public function __construct(
ClientInterface $client,
$subscription_key,
$merchant_serial_number
) {
parent::__construct($client, $subscription_key);
$this->merchantSerialNumber = $merchant_serial_number;
$this->version = 'v1';
}

/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit 4a492f3

Please sign in to comment.