From 9fa503e4d6dbad8d97598f1050d0dc74190ca693 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 10 Jun 2021 11:28:09 +0200 Subject: [PATCH 01/13] Initial work on the recurring payments --- src/Api/RecurringPayment.php | 77 ++++++ src/Api/RecurringPaymentInterface.php | 37 +++ src/Api/UserInfo.php | 38 +++ src/Api/UserInfoInterface.php | 20 ++ src/Model/RecurringPayment/Agreement.php | 218 +++++++++++++++ .../RecurringPayment/CampaignRequest.php | 25 ++ src/Model/RecurringPayment/InitialCharge.php | 43 +++ src/Model/RecurringPayment/Interval.php | 20 ++ .../RequestCreateAgreement.php | 260 ++++++++++++++++++ .../ResponseCreateAgreement.php | 79 ++++++ .../RecurringPayment/ResponseGetAgreement.php | 15 + .../ResponseGetAgreements.php | 0 .../ResponseUpdateAgreement.php | 0 src/Model/RecurringPayment/Status.php | 21 ++ .../RecurringPayment/TransactionType.php | 19 ++ src/Model/UserInfo/AccountInfo.php | 31 +++ src/Model/UserInfo/Address.php | 84 ++++++ src/Model/UserInfo/ResponseUserInfo.php | 86 ++++++ .../RecurringPayment/CreateAgreement.php | 64 +++++ .../RecurringPayment/GetAgreement.php | 58 ++++ .../RecurringPaymentResourceBase.php | 40 +++ src/Resource/UserInfo/UserInfo.php | 65 +++++ src/Vipps.php | 21 ++ 23 files changed, 1321 insertions(+) create mode 100644 src/Api/RecurringPayment.php create mode 100644 src/Api/RecurringPaymentInterface.php create mode 100644 src/Api/UserInfo.php create mode 100644 src/Api/UserInfoInterface.php create mode 100644 src/Model/RecurringPayment/Agreement.php create mode 100644 src/Model/RecurringPayment/CampaignRequest.php create mode 100644 src/Model/RecurringPayment/InitialCharge.php create mode 100644 src/Model/RecurringPayment/Interval.php create mode 100644 src/Model/RecurringPayment/RequestCreateAgreement.php create mode 100644 src/Model/RecurringPayment/ResponseCreateAgreement.php create mode 100644 src/Model/RecurringPayment/ResponseGetAgreement.php create mode 100644 src/Model/RecurringPayment/ResponseGetAgreements.php create mode 100644 src/Model/RecurringPayment/ResponseUpdateAgreement.php create mode 100644 src/Model/RecurringPayment/Status.php create mode 100644 src/Model/RecurringPayment/TransactionType.php create mode 100644 src/Model/UserInfo/AccountInfo.php create mode 100644 src/Model/UserInfo/Address.php create mode 100644 src/Model/UserInfo/ResponseUserInfo.php create mode 100644 src/Resource/RecurringPayment/CreateAgreement.php create mode 100644 src/Resource/RecurringPayment/GetAgreement.php create mode 100644 src/Resource/RecurringPayment/RecurringPaymentResourceBase.php create mode 100644 src/Resource/UserInfo/UserInfo.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php new file mode 100644 index 0000000..432663d --- /dev/null +++ b/src/Api/RecurringPayment.php @@ -0,0 +1,77 @@ +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); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement $response */ + $response = $resource->call(); + return $response; + } + + /** + * {@inheritdoc} + */ + public function getAgreement($agreement_id) + { + $resource = new GetAgreement($this->app, $this->getSubscriptionKey(), $agreement_id); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement $response */ + $response = $resource->call(); + return $response; + } +} diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php new file mode 100644 index 0000000..3487b02 --- /dev/null +++ b/src/Api/RecurringPaymentInterface.php @@ -0,0 +1,37 @@ +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; + } +} diff --git a/src/Api/UserInfoInterface.php b/src/Api/UserInfoInterface.php new file mode 100644 index 0000000..44a7946 --- /dev/null +++ b/src/Api/UserInfoInterface.php @@ -0,0 +1,20 @@ +") + */ + 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. + * + * @return string + */ + 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. + * + * @return string + */ + public function getProductDescription() + { + return $this->productDescription; + } + + /** + * Gets productName value. + * + * @return string + */ + public function getProductName() + { + return $this->productName; + } + + /** + * Gets status value. + * + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * Gets sub value. + * + * @return string + */ + public function getSub() + { + return $this->sub; + } + + /** + * Gets tags value. + * + * @return string[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * Gets userInfoUrl value. + * + * @return string + */ + public function getUserInfoUrl() + { + return $this->userInfoUrl; + } +} diff --git a/src/Model/RecurringPayment/CampaignRequest.php b/src/Model/RecurringPayment/CampaignRequest.php new file mode 100644 index 0000000..e72df15 --- /dev/null +++ b/src/Model/RecurringPayment/CampaignRequest.php @@ -0,0 +1,25 @@ +") + */ + protected $end; +} diff --git a/src/Model/RecurringPayment/InitialCharge.php b/src/Model/RecurringPayment/InitialCharge.php new file mode 100644 index 0000000..41e1a7a --- /dev/null +++ b/src/Model/RecurringPayment/InitialCharge.php @@ -0,0 +1,43 @@ +campaign = $campaign; + return $this; + } + + /** + * Sets currency variable. + * + * @param string $currency + * + * @return $this + */ + public function setCurrency($currency) + { + $this->currency = $currency; + return $this; + } + + /** + * Sets customerPhoneNumber variable. + * + * @param string $customerPhoneNumber + * + * @return $this + */ + public function setCustomerPhoneNumber($customerPhoneNumber) + { + $this->customerPhoneNumber = $customerPhoneNumber; + return $this; + } + + /** + * Sets initialCharge variable. + * + * @param \zaporylie\Vipps\Model\RecurringPayment\InitialCharge $initialCharge + * + * @return $this + */ + public function setInitialCharge(InitialCharge $initialCharge) + { + $this->initialCharge = $initialCharge; + return $this; + } + + /** + * Sets interval variable. + * + * @param string $interval + * + * @return $this + */ + public function setInterval($interval) + { + $this->interval = $interval; + return $this; + } + + /** + * Sets intervalCount variable. + * + * @param int $intervalCount + * + * @return $this + */ + public function setIntervalCount($intervalCount) + { + $this->intervalCount = $intervalCount; + return $this; + } + + /** + * Sets isApp variable. + * + * @param bool $isApp + * + * @return $this + */ + public function setIsApp($isApp) + { + $this->isApp = $isApp; + return $this; + } + + /** + * Sets merchantAgreementUrl variable. + * + * @param string $merchantAgreementUrl + * + * @return $this + */ + public function setMerchantAgreementUrl($merchantAgreementUrl) + { + $this->merchantAgreementUrl = $merchantAgreementUrl; + return $this; + } + + /** + * Sets merchantRedirectUrl variable. + * + * @param string $merchantRedirectUrl + * + * @return $this + */ + public function setMerchantRedirectUrl($merchantRedirectUrl) + { + $this->merchantRedirectUrl = $merchantRedirectUrl; + return $this; + } + + /** + * Sets price variable. + * + * @param int $price + * + * @return $this + */ + public function setPrice($price) + { + $this->price = $price; + return $this; + } + + /** + * Sets productDescription variable. + * + * @param string $productDescription + * + * @return $this + */ + public function setProductDescription($productDescription) + { + $this->productDescription = $productDescription; + return $this; + } + + /** + * Sets productName variable. + * + * @param string $productName + * + * @return $this + */ + public function setProductName($productName) + { + $this->productName = $productName; + return $this; + } + + /** + * Sets scope variable. + * + * @param string $scope + * + * @return $this + */ + public function setScope($scope) + { + $this->scope = $scope; + return $this; + } +} diff --git a/src/Model/RecurringPayment/ResponseCreateAgreement.php b/src/Model/RecurringPayment/ResponseCreateAgreement.php new file mode 100644 index 0000000..87ca3a2 --- /dev/null +++ b/src/Model/RecurringPayment/ResponseCreateAgreement.php @@ -0,0 +1,79 @@ +agreementResource; + } + + /** + * Gets agreementId value. + * + * @return string + */ + public function getAgreementId() + { + return $this->agreementId; + } + + /** + * Gets vippsConfirmetionUrl value. + * + * @return string + */ + public function getVippsConfirmationUrl() + { + return $this->vippsConfirmationUrl; + } + + /** + * Gets chargeId value. + * + * @return string + */ + public function getChargeId() + { + return $this->chargeId; + } + +} diff --git a/src/Model/RecurringPayment/ResponseGetAgreement.php b/src/Model/RecurringPayment/ResponseGetAgreement.php new file mode 100644 index 0000000..4c61cfe --- /dev/null +++ b/src/Model/RecurringPayment/ResponseGetAgreement.php @@ -0,0 +1,15 @@ +addressLine1; + } + + /** + * @return string + */ + public function getAddressLine2() + { + return $this->addressLine2; + } + + /** + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * @return string + */ + public function getCountry() + { + return $this->country; + } + + /** + * @return string + */ + public function getPostCode() + { + return $this->postCode; + } +} diff --git a/src/Model/UserInfo/ResponseUserInfo.php b/src/Model/UserInfo/ResponseUserInfo.php new file mode 100644 index 0000000..7deec7e --- /dev/null +++ b/src/Model/UserInfo/ResponseUserInfo.php @@ -0,0 +1,86 @@ +") + */ + protected $accounts; + + /** + * @var \zaporylie\Vipps\Model\UserInfo\Address + * @Serializer\Type("zaporylie\Vipps\Model\UserInfo\Address") + */ + protected $address; + + /** + * @var \zaporylie\Vipps\Model\UserInfo\Address[] + * @Serializer\Type("array") + */ + protected $other_addresses; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $birthday; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $email; + + /** + * @var bool + * @Serializer\Type("boolean") + */ + protected $email_verified; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $family_name; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $given_name; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $name; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $nin; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $phone_number; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $sid; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $sub; +} diff --git a/src/Resource/RecurringPayment/CreateAgreement.php b/src/Resource/RecurringPayment/CreateAgreement.php new file mode 100644 index 0000000..ed05aee --- /dev/null +++ b/src/Resource/RecurringPayment/CreateAgreement.php @@ -0,0 +1,64 @@ +body = $this + ->getSerializer() + ->serialize( + $requestObject, + 'json' + ); + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + ResponseCreateAgreement::class, + 'json' + ); + + return $responseObject; + } +} diff --git a/src/Resource/RecurringPayment/GetAgreement.php b/src/Resource/RecurringPayment/GetAgreement.php new file mode 100644 index 0000000..8333028 --- /dev/null +++ b/src/Resource/RecurringPayment/GetAgreement.php @@ -0,0 +1,58 @@ +id = $agreement_id; + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + ResponseGetAgreement::class, + 'json' + ); + + return $responseObject; + } +} diff --git a/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php b/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php new file mode 100644 index 0000000..e37ccaa --- /dev/null +++ b/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php @@ -0,0 +1,40 @@ +serializer = SerializerBuilder::create() + ->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy())) + ->build(); + + // Content type for all requests must be set. + $this->headers['Content-Type'] = 'application/json'; + + // By default RequestID is different for each Resource object. + $this->headers['X-Request-Id'] = RequestIdFactory::generate(); + + // Timestamp is equal to current DateTime. + $this->headers['X-TimeStamp'] = (new \DateTime())->format(\DateTime::ISO8601); + } +} diff --git a/src/Resource/UserInfo/UserInfo.php b/src/Resource/UserInfo/UserInfo.php new file mode 100644 index 0000000..e9fe519 --- /dev/null +++ b/src/Resource/UserInfo/UserInfo.php @@ -0,0 +1,65 @@ +app = $vipps; + // Initiate serializer. + $this->serializer = SerializerBuilder::create() + ->build(); + $this->id = $sub; + $this->headers['Authorization'] = + $this->app->getClient()->getTokenStorage()->get()->getTokenType() + .' '. + $this->app->getClient()->getTokenStorage()->get()->getAccessToken(); + } + + /** + * @return \zaporylie\Vipps\Model\UserInfo\ResponseUserInfo + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\UserInfo\ResponseUserInfo $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + ResponseUserInfo::class, + 'json' + ); + + return $responseObject; + } +} diff --git a/src/Vipps.php b/src/Vipps.php index d073880..98f6fb5 100644 --- a/src/Vipps.php +++ b/src/Vipps.php @@ -10,6 +10,8 @@ use zaporylie\Vipps\Api\Authorization; use zaporylie\Vipps\Api\Payment; +use zaporylie\Vipps\Api\RecurringPayment; +use zaporylie\Vipps\Api\UserInfo; /** * Class Vipps @@ -53,6 +55,25 @@ public function payment($subscription_key, $merchant_serial_number, $custom_path return new Payment($this, $subscription_key, $merchant_serial_number, $custom_path); } + /** + * @param string $subscription_key + * @param string $merchant_serial_number + * + * @return \zaporylie\Vipps\Api\RecurringPaymentInterface + */ + public function recurringPayment($subscription_key, $merchant_serial_number) + { + return new RecurringPayment($this, $subscription_key, $merchant_serial_number); + } + + /** + * @return \zaporylie\Vipps\Api\UserInfoInterface + */ + public function userInfo() + { + return new UserInfo($this); + } + /** * @param string $subscription_key * From a1e6bba8376992c4f83712bcbe9a7c77f50d7e5f Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 15 Sep 2021 11:42:35 +0200 Subject: [PATCH 02/13] Update VippsInterface --- src/VippsInterface.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/VippsInterface.php b/src/VippsInterface.php index ba3f805..60ec7d5 100644 --- a/src/VippsInterface.php +++ b/src/VippsInterface.php @@ -23,7 +23,7 @@ public function getClient(); /** * @param string $subscription_key * - * @return \zaporylie\Vipps\Api\Authorization + * @return \zaporylie\Vipps\Api\AuthorizationInterface */ public function authorization($subscription_key); @@ -32,7 +32,15 @@ public function authorization($subscription_key); * @param string $merchant_serial_number * @param string $custom_path * - * @return \zaporylie\Vipps\Api\Payment + * @return \zaporylie\Vipps\Api\PaymentInterface */ public function payment($subscription_key, $merchant_serial_number, $custom_path); + + /** + * @param string $subscription_key + * @param string $merchant_serial_number + * + * @return \zaporylie\Vipps\Api\RecurringPaymentInterface + */ + public function recurringPayment($subscription_key, $merchant_serial_number); } From 154be04327457b49593a6730a8d6228c2088d369 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 15 Sep 2021 12:27:23 +0200 Subject: [PATCH 03/13] Allow fetching all agreements --- src/Api/RecurringPayment.php | 11 +++++ src/Api/RecurringPaymentInterface.php | 10 ++--- .../ResponseGetAgreements.php | 0 .../RecurringPayment/GetAgreements.php | 44 +++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) delete mode 100644 src/Model/RecurringPayment/ResponseGetAgreements.php create mode 100644 src/Resource/RecurringPayment/GetAgreements.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index 432663d..c3438d0 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -6,6 +6,7 @@ use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; use zaporylie\Vipps\Resource\RecurringPayment\CreateAgreement; use zaporylie\Vipps\Resource\RecurringPayment\GetAgreement; +use zaporylie\Vipps\Resource\RecurringPayment\GetAgreements; use zaporylie\Vipps\VippsInterface; /** @@ -64,6 +65,16 @@ public function createAgreement(RequestCreateAgreement $request) return $response; } + /** + * {@inheritdoc} + */ + public function getAgreements() + { + $resource = new GetAgreements($this->app, $this->getSubscriptionKey()); + $response = $resource->call(); + return $response; + } + /** * {@inheritdoc} */ diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index 3487b02..c1c7ad6 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -19,11 +19,11 @@ interface RecurringPaymentInterface */ public function createAgreement(RequestCreateAgreement $requestCreateAgreement); -// /** -// * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreements -// */ -// public function getAgreements(); -// + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[] + */ + public function getAgreements(); + /** * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement */ diff --git a/src/Model/RecurringPayment/ResponseGetAgreements.php b/src/Model/RecurringPayment/ResponseGetAgreements.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Resource/RecurringPayment/GetAgreements.php b/src/Resource/RecurringPayment/GetAgreements.php new file mode 100644 index 0000000..0d6a559 --- /dev/null +++ b/src/Resource/RecurringPayment/GetAgreements.php @@ -0,0 +1,44 @@ +makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[] $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + sprintf("array<%s>", ResponseGetAgreement::class), + 'json' + ); + + return $responseObject; + } +} From 76932e106b8dff9c78a8e77db72972f64b9ccff7 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 17 Sep 2021 13:31:04 +0200 Subject: [PATCH 04/13] Update agreement --- src/Api/RecurringPayment.php | 14 ++- src/Api/RecurringPaymentInterface.php | 14 ++- src/Api/UserInfo.php | 2 - .../RequestUpdateAgreement.php | 109 ++++++++++++++++++ .../ResponseUpdateAgreement.php | 21 ++++ src/Resource/HttpMethod.php | 1 + .../RecurringPayment/UpdateAgreement.php | 70 +++++++++++ 7 files changed, 222 insertions(+), 9 deletions(-) create mode 100644 src/Model/RecurringPayment/RequestUpdateAgreement.php create mode 100644 src/Resource/RecurringPayment/UpdateAgreement.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index c3438d0..586058b 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -4,9 +4,11 @@ use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; use zaporylie\Vipps\Resource\RecurringPayment\CreateAgreement; use zaporylie\Vipps\Resource\RecurringPayment\GetAgreement; use zaporylie\Vipps\Resource\RecurringPayment\GetAgreements; +use zaporylie\Vipps\Resource\RecurringPayment\UpdateAgreement; use zaporylie\Vipps\VippsInterface; /** @@ -60,7 +62,6 @@ public function __construct( public function createAgreement(RequestCreateAgreement $request) { $resource = new CreateAgreement($this->app, $this->getSubscriptionKey(), $request); - /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement $response */ $response = $resource->call(); return $response; } @@ -81,7 +82,16 @@ public function getAgreements() public function getAgreement($agreement_id) { $resource = new GetAgreement($this->app, $this->getSubscriptionKey(), $agreement_id); - /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement $response */ + $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; } diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index c1c7ad6..ea2e026 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -3,6 +3,7 @@ namespace zaporylie\Vipps\Api; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; /** * Interface PaymentInterface @@ -28,10 +29,13 @@ public function getAgreements(); * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement */ public function getAgreement($agreement_id); -// -// /** -// * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreements -// */ -// public function updateAgreement($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); } diff --git a/src/Api/UserInfo.php b/src/Api/UserInfo.php index 42b3d66..155a43d 100644 --- a/src/Api/UserInfo.php +++ b/src/Api/UserInfo.php @@ -2,8 +2,6 @@ namespace zaporylie\Vipps\Api; -use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; -use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; use zaporylie\Vipps\Resource\UserInfo\UserInfo as UserInfoResource; use zaporylie\Vipps\VippsInterface; diff --git a/src/Model/RecurringPayment/RequestUpdateAgreement.php b/src/Model/RecurringPayment/RequestUpdateAgreement.php new file mode 100644 index 0000000..16e9bc7 --- /dev/null +++ b/src/Model/RecurringPayment/RequestUpdateAgreement.php @@ -0,0 +1,109 @@ +campaign = $campaign; + return $this; + } + + /** + * Sets price variable. + * + * @param int $price + * + * @return $this + */ + public function setPrice($price) + { + $this->price = $price; + return $this; + } + + /** + * Sets productDescription variable. + * + * @param string $productDescription + * + * @return $this + */ + public function setProductDescription($productDescription) + { + $this->productDescription = $productDescription; + return $this; + } + + /** + * Sets productName variable. + * + * @param string $productName + * + * @return $this + */ + public function setProductName($productName) + { + $this->productName = $productName; + return $this; + } + + /** + * Sets status variable. + * + * @param string $status + * + * @return $this + */ + public function setStatus($status) + { + $this->status = $status; + return $this; + } + +} diff --git a/src/Model/RecurringPayment/ResponseUpdateAgreement.php b/src/Model/RecurringPayment/ResponseUpdateAgreement.php index e69de29..98e1b08 100644 --- a/src/Model/RecurringPayment/ResponseUpdateAgreement.php +++ b/src/Model/RecurringPayment/ResponseUpdateAgreement.php @@ -0,0 +1,21 @@ +id = $agreement_id; + $this->body = $this + ->getSerializer() + ->serialize( + $requestObject, + 'json' + ); + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + ResponseUpdateAgreement::class, + 'json' + ); + + return $responseObject; + } +} From 981133faecc32fdd5bd7f347bbbf6f173fb394ff Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Mon, 20 Sep 2021 11:47:49 +0200 Subject: [PATCH 05/13] Create and get charges --- src/Api/RecurringPayment.php | 23 ++++ src/Api/RecurringPaymentInterface.php | 15 +++ src/Model/RecurringPayment/Charge.php | 73 ++++++++++ .../RecurringPayment/RequestCreateCharge.php | 127 ++++++++++++++++++ .../RecurringPayment/ResponseCreateCharge.php | 30 +++++ .../RecurringPayment/ResponseGetCharge.php | 15 +++ src/Resource/IdempotencyKeyFactory.php | 22 +++ .../RecurringPayment/CreateCharge.php | 74 ++++++++++ src/Resource/RecurringPayment/GetCharges.php | 53 ++++++++ 9 files changed, 432 insertions(+) create mode 100644 src/Model/RecurringPayment/Charge.php create mode 100644 src/Model/RecurringPayment/RequestCreateCharge.php create mode 100644 src/Model/RecurringPayment/ResponseCreateCharge.php create mode 100644 src/Model/RecurringPayment/ResponseGetCharge.php create mode 100644 src/Resource/IdempotencyKeyFactory.php create mode 100644 src/Resource/RecurringPayment/CreateCharge.php create mode 100644 src/Resource/RecurringPayment/GetCharges.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index 586058b..6e8e0f6 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -4,10 +4,13 @@ use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; 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\GetCharges; use zaporylie\Vipps\Resource\RecurringPayment\UpdateAgreement; use zaporylie\Vipps\VippsInterface; @@ -95,4 +98,24 @@ public function updateAgreement($agreement_id, RequestUpdateAgreement $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 createCharge($agreement_id, RequestCreateCharge $request) + { + $resource = new CreateCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $request); + $response = $resource->call(); + return $response; + } } diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index ea2e026..a6def65 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -3,6 +3,7 @@ namespace zaporylie\Vipps\Api; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; /** @@ -38,4 +39,18 @@ public function getAgreement($agreement_id); */ 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 \zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge $request + * + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateCharge + */ + public function createCharge($agreement_id, RequestCreateCharge $request); } diff --git a/src/Model/RecurringPayment/Charge.php b/src/Model/RecurringPayment/Charge.php new file mode 100644 index 0000000..12184da --- /dev/null +++ b/src/Model/RecurringPayment/Charge.php @@ -0,0 +1,73 @@ +") + */ + protected $due; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $id; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $status; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $transactionId; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $type; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $failureReason; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $failureDescription; +} diff --git a/src/Model/RecurringPayment/RequestCreateCharge.php b/src/Model/RecurringPayment/RequestCreateCharge.php new file mode 100644 index 0000000..8c03e92 --- /dev/null +++ b/src/Model/RecurringPayment/RequestCreateCharge.php @@ -0,0 +1,127 @@ +") + */ + protected $due; + + /** + * @var int + * @Serializer\Type("integer") + */ + protected $retryDays = 0; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $orderId; + + /** + * Sets amount variable. + * + * @param int $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * Sets currency variable. + * + * @param string $currency + * + * @return $this + */ + public function setCurrency($currency) + { + $this->currency = $currency; + return $this; + } + + /** + * Sets description variable. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Sets due variable. + * + * @param \DateTimeInterface $due + * + * @return $this + */ + public function setDue(\DateTimeInterface $due) + { + $this->due = $due; + return $this; + } + + /** + * Sets retryDays variable. + * + * @param int $retryDays + * + * @return $this + */ + public function setRetryDays($retryDays) + { + $this->retryDays = $retryDays; + return $this; + } + + /** + * Sets orderId variable. + * + * @param string $orderId + * + * @return $this + */ + public function setOrderId($orderId) + { + $this->orderId = $orderId; + return $this; + } +} diff --git a/src/Model/RecurringPayment/ResponseCreateCharge.php b/src/Model/RecurringPayment/ResponseCreateCharge.php new file mode 100644 index 0000000..da4d7f3 --- /dev/null +++ b/src/Model/RecurringPayment/ResponseCreateCharge.php @@ -0,0 +1,30 @@ +chargeId; + } +} diff --git a/src/Model/RecurringPayment/ResponseGetCharge.php b/src/Model/RecurringPayment/ResponseGetCharge.php new file mode 100644 index 0000000..283ac63 --- /dev/null +++ b/src/Model/RecurringPayment/ResponseGetCharge.php @@ -0,0 +1,15 @@ +id = $agreementId; + // By default RequestID is different for each Resource object. + $this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate(); + parent::__construct($vipps, $subscription_key); + $this->body = $this + ->getSerializer() + ->serialize( + $requestObject, + 'json' + ); + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateCharge + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateCharge $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + ResponseCreateCharge::class, + 'json' + ); + + return $responseObject; + } +} diff --git a/src/Resource/RecurringPayment/GetCharges.php b/src/Resource/RecurringPayment/GetCharges.php new file mode 100644 index 0000000..541b99e --- /dev/null +++ b/src/Resource/RecurringPayment/GetCharges.php @@ -0,0 +1,53 @@ +id = $agreement_id; + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\Charge[] + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\Charge[] $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + sprintf("array<%s>", Charge::class), + 'json' + ); + + return $responseObject; + } +} From c55cdcb56193f645a17dea5c8cf9fb2be1e29b1d Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 21 Sep 2021 09:33:12 +0200 Subject: [PATCH 06/13] Add support for obtaining and capturing single charge --- src/Api/RecurringPayment.php | 22 +++++++ src/Api/RecurringPaymentInterface.php | 16 +++++ src/Model/RecurringPayment/InitialCharge.php | 65 +++++++++++++++++++ .../ResponseCaptureCharge.php | 15 +++++ .../RecurringPayment/CaptureCharge.php | 61 +++++++++++++++++ src/Resource/RecurringPayment/GetCharge.php | 55 ++++++++++++++++ .../RecurringPaymentResourceBase.php | 21 ++++++ 7 files changed, 255 insertions(+) create mode 100644 src/Model/RecurringPayment/ResponseCaptureCharge.php create mode 100644 src/Resource/RecurringPayment/CaptureCharge.php create mode 100644 src/Resource/RecurringPayment/GetCharge.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index 6e8e0f6..9616cf2 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -6,10 +6,12 @@ use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; +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\UpdateAgreement; use zaporylie\Vipps\VippsInterface; @@ -109,6 +111,16 @@ public function getCharges($agreement_id) 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} */ @@ -118,4 +130,14 @@ public function createCharge($agreement_id, RequestCreateCharge $request) $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; + } } diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index a6def65..46d1b44 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -46,6 +46,14 @@ public function updateAgreement($agreement_id, RequestUpdateAgreement $request); */ 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 @@ -53,4 +61,12 @@ public function getCharges($agreement_id); * @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 captureCharge($agreement_id, $charge_id); } diff --git a/src/Model/RecurringPayment/InitialCharge.php b/src/Model/RecurringPayment/InitialCharge.php index 41e1a7a..186ecde 100644 --- a/src/Model/RecurringPayment/InitialCharge.php +++ b/src/Model/RecurringPayment/InitialCharge.php @@ -40,4 +40,69 @@ class InitialCharge * @Serializer\Type("string") */ protected $orderId; + + /** + * Sets amount variable. + * + * @param int $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * Sets currency variable. + * + * @param string $currency + * + * @return $this + */ + public function setCurrency($currency) + { + $this->currency = $currency; + return $this; + } + + /** + * Sets description variable. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Sets transactionType variable. + * + * @param string $transactionType + * + * @return $this + */ + public function setTransactionType($transactionType) + { + $this->transactionType = $transactionType; + return $this; + } + + /** + * Sets orderId variable. + * + * @param string $orderId + * + * @return $this + */ + public function setOrderId($orderId) + { + $this->orderId = $orderId; + return $this; + } } diff --git a/src/Model/RecurringPayment/ResponseCaptureCharge.php b/src/Model/RecurringPayment/ResponseCaptureCharge.php new file mode 100644 index 0000000..7df709f --- /dev/null +++ b/src/Model/RecurringPayment/ResponseCaptureCharge.php @@ -0,0 +1,15 @@ +id = $agreement_id; + $this->charge_id = $charge_id; + // By default RequestID is different for each Resource object. + $this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate(); + parent::__construct($vipps, $subscription_key); + } + + /** + * @return string + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + return $body; + } +} diff --git a/src/Resource/RecurringPayment/GetCharge.php b/src/Resource/RecurringPayment/GetCharge.php new file mode 100644 index 0000000..3029f10 --- /dev/null +++ b/src/Resource/RecurringPayment/GetCharge.php @@ -0,0 +1,55 @@ +id = $agreement_id; + $this->charge_id = $charge_id; + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\Charge + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + /** @var \zaporylie\Vipps\Model\RecurringPayment\Charge $responseObject */ + $responseObject = $this + ->getSerializer() + ->deserialize( + $body, + Charge::class, + 'json' + ); + + return $responseObject; + } +} diff --git a/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php b/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php index e37ccaa..7af5980 100644 --- a/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php +++ b/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php @@ -16,6 +16,11 @@ abstract class RecurringPaymentResourceBase extends AuthorizedResourceBase { + /** + * @var string + */ + protected $charge_id; + /** * {@inheritdoc} */ @@ -37,4 +42,20 @@ public function __construct(\zaporylie\Vipps\VippsInterface $vipps, $subscriptio // Timestamp is equal to current DateTime. $this->headers['X-TimeStamp'] = (new \DateTime())->format(\DateTime::ISO8601); } + + + /** + * {@inheritdoc} + * + * All occurrences of {id} pattern will be replaced with $this->id + */ + public function getPath() + { + $path = parent::getPath(); + // If ID is set replace {id} pattern with model's ID. + if (isset($this->charge_id)) { + $path = str_replace('{charge_id}', $this->charge_id, $path); + } + return $path; + } } From dc15fcc509ed52572f77ed613f5a472cb144b3c7 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 22 Sep 2021 21:37:30 +0200 Subject: [PATCH 07/13] Allow correctly fetching start and end dates --- src/Model/RecurringPayment/Agreement.php | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Model/RecurringPayment/Agreement.php b/src/Model/RecurringPayment/Agreement.php index a8958f6..3889efd 100644 --- a/src/Model/RecurringPayment/Agreement.php +++ b/src/Model/RecurringPayment/Agreement.php @@ -61,14 +61,14 @@ class Agreement protected $productDescription; /** - * @var string - * @Serializer\Type("string") + * @var \DateTimeInterface + * @Serializer\Type("DateTime<'Y-m-d\TH:i:s\Z'>") */ protected $start; /** - * @var string - * @Serializer\Type("string") + * @var \DateTimeInterface + * @Serializer\Type("DateTime<'Y-m-d\TH:i:s\Z'>") */ protected $stop; @@ -166,6 +166,26 @@ public function getProductDescription() return $this->productDescription; } + /** + * Gets start value. + * + * @return string + */ + public function getStart() + { + return $this->start; + } + + /** + * Gets stop value. + * + * @return string + */ + public function getStop() + { + return $this->stop; + } + /** * Gets productName value. * From 4b5a7522a498ffe3181dbf4144387f57fb7c2df8 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 22 Sep 2021 21:39:43 +0200 Subject: [PATCH 08/13] Add missing getters for models --- src/Model/RecurringPayment/Charge.php | 100 ++++++++++++++++++ .../ResponseUpdateAgreement.php | 10 ++ 2 files changed, 110 insertions(+) diff --git a/src/Model/RecurringPayment/Charge.php b/src/Model/RecurringPayment/Charge.php index 12184da..d95c728 100644 --- a/src/Model/RecurringPayment/Charge.php +++ b/src/Model/RecurringPayment/Charge.php @@ -70,4 +70,104 @@ class Charge * @Serializer\Type("string") */ protected $failureDescription; + + /** + * Gets amount value. + * + * @return int + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Gets amountRefunded value. + * + * @return int + */ + public function getAmountRefunded() + { + return $this->amountRefunded; + } + + /** + * Gets description value. + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Gets due value. + * + * @return \DateTimeInterface + */ + public function getDue() + { + return $this->due; + } + + /** + * Gets failureDescription value. + * + * @return string + */ + public function getFailureDescription() + { + return $this->failureDescription; + } + + /** + * Gets failureReason value. + * + * @return string + */ + public function getFailureReason() + { + return $this->failureReason; + } + + /** + * Gets id value. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Gets status value. + * + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * Gets transactionId value. + * + * @return string + */ + public function getTransactionId() + { + return $this->transactionId; + } + + /** + * Gets type value. + * + * @return string + */ + public function getType() + { + return $this->type; + } } diff --git a/src/Model/RecurringPayment/ResponseUpdateAgreement.php b/src/Model/RecurringPayment/ResponseUpdateAgreement.php index 98e1b08..1cb558a 100644 --- a/src/Model/RecurringPayment/ResponseUpdateAgreement.php +++ b/src/Model/RecurringPayment/ResponseUpdateAgreement.php @@ -18,4 +18,14 @@ class ResponseUpdateAgreement */ protected $agreementId; + /** + * Gets agreementId value. + * + * @return string + */ + public function getAgreementId() + { + return $this->agreementId; + } + } From ba2645955950b60377c9f9f18e4bb0bb890584cb Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 22 Sep 2021 23:27:12 +0200 Subject: [PATCH 09/13] Add getters for user info --- src/Model/UserInfo/ResponseUserInfo.php | 120 ++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/src/Model/UserInfo/ResponseUserInfo.php b/src/Model/UserInfo/ResponseUserInfo.php index 7deec7e..77115ad 100644 --- a/src/Model/UserInfo/ResponseUserInfo.php +++ b/src/Model/UserInfo/ResponseUserInfo.php @@ -83,4 +83,124 @@ class ResponseUserInfo * @Serializer\Type("string") */ protected $sub; + + /** + * Gets accounts value. + * + * @return \zaporylie\Vipps\Model\UserInfo\AccountInfo[] + */ + public function getAccounts() + { + return $this->accounts; + } + + /** + * Gets address value. + * + * @return \zaporylie\Vipps\Model\UserInfo\Address + */ + public function getAddress() + { + return $this->address; + } + + /** + * Gets birthday value. + * + * @return string + */ + public function getBirthday() + { + return $this->birthday; + } + + /** + * Gets email value. + * + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * Gets family_name value. + * + * @return string + */ + public function getFamilyName() + { + return $this->family_name; + } + + /** + * Gets given_name value. + * + * @return string + */ + public function getGivenName() + { + return $this->given_name; + } + + /** + * Gets name value. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Gets nin value. + * + * @return string + */ + public function getNin() + { + return $this->nin; + } + + /** + * Gets other_addresses value. + * + * @return \zaporylie\Vipps\Model\UserInfo\Address[] + */ + public function getOtherAddresses() + { + return $this->other_addresses; + } + + /** + * Gets phone_number value. + * + * @return string + */ + public function getPhoneNumber() + { + return $this->phone_number; + } + + /** + * Gets sid value. + * + * @return string + */ + public function getSid() + { + return $this->sid; + } + + /** + * Gets sub value. + * + * @return string + */ + public function getSub() + { + return $this->sub; + } } From 008437fc57f71d759bb83bba06f3c920683f2c2c Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 23 Sep 2021 09:23:10 +0200 Subject: [PATCH 10/13] Add support for refunds --- src/Api/RecurringPayment.php | 18 +++++ src/Api/RecurringPaymentInterface.php | 10 +++ .../RecurringPayment/RequestRefundCharge.php | 52 ++++++++++++++ .../RecurringPayment/RefundCharge.php | 70 +++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 src/Model/RecurringPayment/RequestRefundCharge.php create mode 100644 src/Resource/RecurringPayment/RefundCharge.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index 9616cf2..d31b041 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -5,6 +5,7 @@ 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\CaptureCharge; use zaporylie\Vipps\Resource\RecurringPayment\CreateAgreement; @@ -13,6 +14,7 @@ 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; @@ -140,4 +142,20 @@ public function captureCharge($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; + } } diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index 46d1b44..cac65ca 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -4,6 +4,7 @@ use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; +use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge; use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; /** @@ -69,4 +70,13 @@ public function createCharge($agreement_id, RequestCreateCharge $request); * @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); } diff --git a/src/Model/RecurringPayment/RequestRefundCharge.php b/src/Model/RecurringPayment/RequestRefundCharge.php new file mode 100644 index 0000000..482fd14 --- /dev/null +++ b/src/Model/RecurringPayment/RequestRefundCharge.php @@ -0,0 +1,52 @@ +amount = $amount; + return $this; + } + + /** + * Sets description variable. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + +} diff --git a/src/Resource/RecurringPayment/RefundCharge.php b/src/Resource/RecurringPayment/RefundCharge.php new file mode 100644 index 0000000..6bdcb3b --- /dev/null +++ b/src/Resource/RecurringPayment/RefundCharge.php @@ -0,0 +1,70 @@ +id = $agreement_id; + $this->charge_id = $charge_id; + // By default RequestID is different for each Resource object. + $this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate(); + parent::__construct($vipps, $subscription_key); + $this->body = $this + ->getSerializer() + ->serialize( + $requestObject, + 'json' + ); + } + + /** + * @return string + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + return $body; + } +} From ede5caf3e8f6840498a9488e41b4b064bda753a5 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 23 Sep 2021 09:41:07 +0200 Subject: [PATCH 11/13] Cancel Charge --- src/Api/RecurringPayment.php | 11 ++++ src/Api/RecurringPaymentInterface.php | 8 +++ .../RecurringPayment/CancelCharge.php | 59 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/Resource/RecurringPayment/CancelCharge.php diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index d31b041..51d98b5 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -7,6 +7,7 @@ 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; @@ -133,6 +134,16 @@ public function createCharge($agreement_id, RequestCreateCharge $request) 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} */ diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index cac65ca..2f582ad 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -63,6 +63,14 @@ public function getCharge($agreement_id, $charge_id); */ 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 diff --git a/src/Resource/RecurringPayment/CancelCharge.php b/src/Resource/RecurringPayment/CancelCharge.php new file mode 100644 index 0000000..c734f2c --- /dev/null +++ b/src/Resource/RecurringPayment/CancelCharge.php @@ -0,0 +1,59 @@ +id = $agreement_id; + $this->charge_id = $charge_id; + parent::__construct($vipps, $subscription_key); + } + + /** + * @return string + */ + public function call() + { + $response = $this->makeCall(); + $body = $response->getBody()->getContents(); + return $body; + } +} From c40c94bc39cfde569c0f0a5bb176b704d9215c56 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 23 Sep 2021 14:10:08 +0200 Subject: [PATCH 12/13] Fix user address schema --- src/Model/UserInfo/Address.php | 51 +++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/Model/UserInfo/Address.php b/src/Model/UserInfo/Address.php index fadbba7..b4a4b35 100644 --- a/src/Model/UserInfo/Address.php +++ b/src/Model/UserInfo/Address.php @@ -11,24 +11,23 @@ */ class Address { - /** * @var string * @Serializer\Type("string") */ - protected $addressLine1; + protected $address_type; /** * @var string * @Serializer\Type("string") */ - protected $addressLine2; + protected $street_address; /** * @var string * @Serializer\Type("string") */ - protected $city; + protected $region; /** * @var string @@ -40,33 +39,47 @@ class Address * @var string * @Serializer\Type("string") */ - protected $postCode; + protected $postal_code; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $formatted; /** + * Gets address_type value. + * * @return string */ - public function getAddressLine1() + public function getAddressType() { - return $this->addressLine1; + return $this->address_type; } /** + * Gets street_address value. + * * @return string */ - public function getAddressLine2() + public function getStreetAddress() { - return $this->addressLine2; + return $this->street_address; } /** + * Gets region value. + * * @return string */ - public function getCity() + public function getRegion() { - return $this->city; + return $this->region; } /** + * Gets country value. + * * @return string */ public function getCountry() @@ -75,10 +88,22 @@ public function getCountry() } /** + * Gets postal_code value. + * + * @return string + */ + public function getPostalCode() + { + return $this->postal_code; + } + + /** + * Gets formatted value. + * * @return string */ - public function getPostCode() + public function getFormatted() { - return $this->postCode; + return $this->formatted; } } From d6c5c85636a89239809ab973d72cc96675099dbd Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 6 Oct 2021 14:16:19 +0200 Subject: [PATCH 13/13] Fix code style --- src/Api/UserInfoInterface.php | 1 - src/Model/RecurringPayment/RequestRefundCharge.php | 1 - src/Model/RecurringPayment/RequestUpdateAgreement.php | 1 - src/Model/RecurringPayment/ResponseCreateAgreement.php | 1 - src/Model/RecurringPayment/ResponseUpdateAgreement.php | 1 - 5 files changed, 5 deletions(-) diff --git a/src/Api/UserInfoInterface.php b/src/Api/UserInfoInterface.php index 44a7946..dfa48f9 100644 --- a/src/Api/UserInfoInterface.php +++ b/src/Api/UserInfoInterface.php @@ -2,7 +2,6 @@ namespace zaporylie\Vipps\Api; - /** * Interface UserInfoInterface * diff --git a/src/Model/RecurringPayment/RequestRefundCharge.php b/src/Model/RecurringPayment/RequestRefundCharge.php index 482fd14..21dc59e 100644 --- a/src/Model/RecurringPayment/RequestRefundCharge.php +++ b/src/Model/RecurringPayment/RequestRefundCharge.php @@ -48,5 +48,4 @@ public function setDescription($description) $this->description = $description; return $this; } - } diff --git a/src/Model/RecurringPayment/RequestUpdateAgreement.php b/src/Model/RecurringPayment/RequestUpdateAgreement.php index 16e9bc7..187de85 100644 --- a/src/Model/RecurringPayment/RequestUpdateAgreement.php +++ b/src/Model/RecurringPayment/RequestUpdateAgreement.php @@ -105,5 +105,4 @@ public function setStatus($status) $this->status = $status; return $this; } - } diff --git a/src/Model/RecurringPayment/ResponseCreateAgreement.php b/src/Model/RecurringPayment/ResponseCreateAgreement.php index 87ca3a2..07a943d 100644 --- a/src/Model/RecurringPayment/ResponseCreateAgreement.php +++ b/src/Model/RecurringPayment/ResponseCreateAgreement.php @@ -75,5 +75,4 @@ public function getChargeId() { return $this->chargeId; } - } diff --git a/src/Model/RecurringPayment/ResponseUpdateAgreement.php b/src/Model/RecurringPayment/ResponseUpdateAgreement.php index 1cb558a..b6bfdce 100644 --- a/src/Model/RecurringPayment/ResponseUpdateAgreement.php +++ b/src/Model/RecurringPayment/ResponseUpdateAgreement.php @@ -27,5 +27,4 @@ public function getAgreementId() { return $this->agreementId; } - }