Skip to content

Commit

Permalink
Vipps class is redunant, use Client directly
Browse files Browse the repository at this point in the history
  • Loading branch information
zaporylie committed Jul 30, 2024
1 parent 2c22a48 commit 94f8a58
Show file tree
Hide file tree
Showing 52 changed files with 365 additions and 425 deletions.
14 changes: 7 additions & 7 deletions examples/authorization/01-token.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$result = $authorization->getToken($settings['client_secret']);
echo '<pre>';
var_dump($result);
Expand Down
20 changes: 8 additions & 12 deletions examples/checkout/01-checkout-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], [
'http_client' => $http_client,
'vipps_system_name' => 'vipps_zaporylie_example',
'vipps_system_version' => \zaporylie\Vipps\Client::VERSION,
]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$checkout = new \zaporylie\Vipps\Api\v3\Checkout($vipps, $settings['subscription_key'], $settings['merchant_serial_number'], $settings['client_secret']);
$checkout = new \zaporylie\Vipps\Api\v3\Checkout($client, $settings['subscription_key'], $settings['merchant_serial_number'], $settings['client_secret']);
$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 @@ -7,15 +7,15 @@

try {
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], [
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$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
10 changes: 7 additions & 3 deletions examples/payment/02-epayment-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$result = $payment->getPayment('test-12121212-4');
echo '<pre>';
var_dump($result);
Expand Down
16 changes: 8 additions & 8 deletions examples/payment/03-epayment-adjust-cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$result = $payment->cancelPayment('test-12121212-3', new \zaporylie\Vipps\Model\EPayment\v1\CancelModificationRequest(), 'costam');
echo '<pre>';
var_dump($result);
Expand Down
16 changes: 8 additions & 8 deletions examples/payment/04-epayment-adjust-modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\EPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$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
7 changes: 3 additions & 4 deletions examples/recurring_payment/01-recurring-payment-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

try {
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], [
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$result = $payment->createAgreement((new \zaporylie\Vipps\Model\RecurringPayment\v3\RequestCreateAgreement())
->setPricing((new \zaporylie\Vipps\Model\RecurringPayment\v3\Pricing())
->setCurrency('NOK')
->setType('FLEXIBLE')
->setAmount(1000))
->setMerchantRedirectUrl('https://eoncxehuh2o2qyq.m.pipedream.net')
->setMerchantAgreementUrl('https://eoncxehuh2o2qyq.m.pipedream.net')
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 @@ -7,15 +7,15 @@

try {
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], [
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$result = $payment->getAgreement('agr_KG6k3X3');
echo '<pre>';
var_dump($result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

try {
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], [
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$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 @@ -7,15 +7,15 @@

try {
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], [
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v3\RecurringPayment($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$result = $payment->getCharge('agr_KG6k3X3','chr-gTHPbNE');
echo '<pre>';
var_dump($result);
Expand Down
16 changes: 8 additions & 8 deletions examples/webhook/01-webhook-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$result = $payment->getWebhooks();
echo '<pre>';
var_dump($result);
Expand Down
16 changes: 8 additions & 8 deletions examples/webhook/02-webhook-register.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$request = new \zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookRequest();
$request->setUrl("https://eoncxehuh2o2qyq.m.pipedream.net/");
$request->setEvents([
Expand Down
16 changes: 8 additions & 8 deletions examples/webhook/03-webhook-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
$settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__.'/../config.yml'));

try {
$http_client = new \GuzzleHttp\Client(
['headers' => [
'Merchant-Serial-Number' => $settings['merchant_serial_number'],
]]
);
$client = new \zaporylie\Vipps\Client($settings['client_id'], ['http_client' => $http_client]);
$http_client = new \GuzzleHttp\Client();
$client = new \zaporylie\Vipps\Client($settings['client_id'], $settings['client_secret'], $settings['subscription_key'], $settings['merchant_serial_number'], [
'http_client' => $http_client,
'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($vipps, $settings['subscription_key']);
$authorization = new \zaporylie\Vipps\Api\Authorization($client, $settings['subscription_key']);
$authorization->getToken($settings['client_secret']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($vipps, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment = new \zaporylie\Vipps\Api\v1\Webhook($client, $settings['subscription_key'], $settings['merchant_serial_number']);
$payment->deleteWebhook('1aaf0fde-afed-43c0-9af3-b876bba34e48');
echo 'ok';

Expand Down
19 changes: 6 additions & 13 deletions src/Api/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@

namespace zaporylie\Vipps\Api;

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

abstract class ApiBase
{

/**
* @var \zaporylie\Vipps\VippsInterface
* @var \zaporylie\Vipps\ClientInterface
*/
protected $app;

/**
* @var string
*/
protected $subscriptionKey;
protected $client;

/**
* ApiBase constructor.
*
* @param \zaporylie\Vipps\VippsInterface $app
* @param string $subscription_key
* @param \zaporylie\Vipps\ClientInterface $client
*/
public function __construct(VippsInterface $app, $subscription_key)
public function __construct(ClientInterface $client)
{
$this->app = $app;
$this->subscriptionKey = $subscription_key;
$this->client = $client;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class Authorization extends ApiBase implements AuthorizationInterface
public function getToken($client_secret)
{
// Initiate GetToken resource.
$resource = new GetToken($this->app, $this->getSubscriptionKey(), $client_secret);
$resource = new GetToken($this->client, $client_secret);

/** @var \zaporylie\Vipps\Model\Authorization\ResponseGetToken $response */
$response = $resource->call();

// Save token on Client for future use.
$this->app->getClient()->getTokenStorage()->set($response);
$this->client->getTokenStorage()->set($response);

return $response;
}
Expand Down
Loading

0 comments on commit 94f8a58

Please sign in to comment.