diff --git a/src/Api/RecurringPayment.php b/src/Api/RecurringPayment.php index 51d98b5..b0450ea 100644 --- a/src/Api/RecurringPayment.php +++ b/src/Api/RecurringPayment.php @@ -3,10 +3,11 @@ namespace zaporylie\Vipps\Api; use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; -use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge; -use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase; +use zaporylie\Vipps\Model\RecurringPayment\v3\RequestCaptureCharge; use zaporylie\Vipps\Resource\RecurringPayment\CancelCharge; use zaporylie\Vipps\Resource\RecurringPayment\CaptureCharge; use zaporylie\Vipps\Resource\RecurringPayment\CreateAgreement; @@ -32,6 +33,11 @@ class RecurringPayment extends ApiBase implements RecurringPaymentInterface */ protected $merchantSerialNumber; + /** + * @var int + */ + protected $api_endpoint_version; + /** * Gets merchantSerialNumber value. * @@ -46,30 +52,30 @@ public function getMerchantSerialNumber() } /** - * Payment constructor. - * - * Payments API needs one extra param - merchant serial number. + * Recurring Payments constructor. * * @param \zaporylie\Vipps\VippsInterface $app * @param string $subscription_key * @param $merchant_serial_number - * @param $custom_path + * @param int $api_endpoint_version */ public function __construct( VippsInterface $app, $subscription_key, - $merchant_serial_number + $merchant_serial_number, + $api_endpoint_version ) { parent::__construct($app, $subscription_key); $this->merchantSerialNumber = $merchant_serial_number; + $this->api_endpoint_version = $api_endpoint_version; } /** * {@inheritdoc} */ - public function createAgreement(RequestCreateAgreement $request) + public function createAgreement(RequestCreateAgreementBase $request) { - $resource = new CreateAgreement($this->app, $this->getSubscriptionKey(), $request); + $resource = new CreateAgreement($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $request); $response = $resource->call(); return $response; } @@ -79,7 +85,7 @@ public function createAgreement(RequestCreateAgreement $request) */ public function getAgreements() { - $resource = new GetAgreements($this->app, $this->getSubscriptionKey()); + $resource = new GetAgreements($this->app, $this->api_endpoint_version, $this->getSubscriptionKey()); $response = $resource->call(); return $response; } @@ -89,7 +95,7 @@ public function getAgreements() */ public function getAgreement($agreement_id) { - $resource = new GetAgreement($this->app, $this->getSubscriptionKey(), $agreement_id); + $resource = new GetAgreement($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id); $response = $resource->call(); return $response; } @@ -97,9 +103,9 @@ public function getAgreement($agreement_id) /** * {@inheritdoc} */ - public function updateAgreement($agreement_id, RequestUpdateAgreement $request) + public function updateAgreement($agreement_id, RequestUpdateAgreementBase $request) { - $resource = new UpdateAgreement($this->app, $this->getSubscriptionKey(), $agreement_id, $request); + $resource = new UpdateAgreement($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $request); $response = $resource->call(); return $response; } @@ -109,7 +115,7 @@ public function updateAgreement($agreement_id, RequestUpdateAgreement $request) */ public function getCharges($agreement_id) { - $resource = new GetCharges($this->app, $this->getSubscriptionKey(), $agreement_id); + $resource = new GetCharges($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id); $response = $resource->call(); return $response; } @@ -119,7 +125,7 @@ public function getCharges($agreement_id) */ public function getCharge($agreement_id, $charge_id) { - $resource = new GetCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id); + $resource = new GetCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id); $response = $resource->call(); return $response; } @@ -129,7 +135,7 @@ public function getCharge($agreement_id, $charge_id) */ public function createCharge($agreement_id, RequestCreateCharge $request) { - $resource = new CreateCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $request); + $resource = new CreateCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $request); $response = $resource->call(); return $response; } @@ -139,7 +145,7 @@ public function createCharge($agreement_id, RequestCreateCharge $request) */ public function cancelCharge($agreement_id, $charge_id) { - $resource = new CancelCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id); + $resource = new CancelCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id); $response = $resource->call(); return $response; } @@ -147,9 +153,9 @@ public function cancelCharge($agreement_id, $charge_id) /** * {@inheritDoc} */ - public function captureCharge($agreement_id, $charge_id) + public function captureCharge($agreement_id, $charge_id, RequestCaptureCharge $requestObject) { - $resource = new CaptureCharge($this->app, $this->getSubscriptionKey(), $agreement_id, $charge_id); + $resource = new CaptureCharge($this->app, $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id, $requestObject); $response = $resource->call(); return $response; } @@ -160,7 +166,8 @@ public function captureCharge($agreement_id, $charge_id) public function refundCharge($agreement_id, $charge_id, RequestRefundCharge $requestObject) { $resource = new RefundCharge( - $this->app, + $this->app, + $this->api_endpoint_version, $this->getSubscriptionKey(), $agreement_id, $charge_id, diff --git a/src/Api/RecurringPaymentInterface.php b/src/Api/RecurringPaymentInterface.php index 2f582ad..e516b95 100644 --- a/src/Api/RecurringPaymentInterface.php +++ b/src/Api/RecurringPaymentInterface.php @@ -2,10 +2,11 @@ namespace zaporylie\Vipps\Api; -use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase; use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; use zaporylie\Vipps\Model\RecurringPayment\RequestRefundCharge; -use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase; +use zaporylie\Vipps\Model\RecurringPayment\v3\RequestCaptureCharge; /** * Interface PaymentInterface @@ -16,29 +17,29 @@ interface RecurringPaymentInterface { /** - * @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement + * @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase * * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement */ - public function createAgreement(RequestCreateAgreement $requestCreateAgreement); + public function createAgreement(RequestCreateAgreementBase $requestCreateAgreement); /** - * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[] + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase[] */ public function getAgreements(); /** - * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase */ public function getAgreement($agreement_id); /** * @param $agreement_id - * @param \zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement $request + * @param \zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase $request * * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement */ - public function updateAgreement($agreement_id, RequestUpdateAgreement $request); + public function updateAgreement($agreement_id, RequestUpdateAgreementBase $request); /** * @param $agreement_id @@ -77,7 +78,7 @@ public function cancelCharge($agreement_id, $charge_id); * * @return string */ - public function captureCharge($agreement_id, $charge_id); + public function captureCharge($agreement_id, $charge_id, RequestCaptureCharge $requestObject); /** * @param string $agreement_id diff --git a/src/Model/RecurringPayment/Agreement.php b/src/Model/RecurringPayment/AgreementBase.php similarity index 62% rename from src/Model/RecurringPayment/Agreement.php rename to src/Model/RecurringPayment/AgreementBase.php index 5901c32..bc0da60 100644 --- a/src/Model/RecurringPayment/Agreement.php +++ b/src/Model/RecurringPayment/AgreementBase.php @@ -5,49 +5,18 @@ use JMS\Serializer\Annotation as Serializer; /** - * Class ResponseGetAgreement + * Class AgreementBase * * @package Vipps\Model\RecurringPayment */ -class Agreement +class AgreementBase { - - /** - * @var \zaporylie\Vipps\Model\RecurringPayment\CampaignRequest - * @Serializer\Type("zaporylie\Vipps\Model\RecurringPayment\CampaignRequest") - */ - protected $campaign; - - /** - * @var string - * @Serializer\Type("string") - */ - protected $currency; - /** * @var string * @Serializer\Type("string") */ protected $id; - /** - * @var string - * @Serializer\Type("string") - */ - protected $interval; - - /** - * @var int - * @Serializer\Type("integer") - */ - protected $intervalCount; - - /** - * @var int - * @Serializer\Type("integer") - */ - protected $price; - /** * @var string * @Serializer\Type("string") @@ -96,26 +65,6 @@ class Agreement */ protected $tags; - /** - * Gets campaign value. - * - * @return \zaporylie\Vipps\Model\RecurringPayment\CampaignRequest - */ - public function getCampaign() - { - return $this->campaign; - } - - /** - * Gets currency value. - * - * @return string - */ - public function getCurrency() - { - return $this->currency; - } - /** * Gets id value. * @@ -126,36 +75,6 @@ public function getId() return $this->id; } - /** - * Gets interval value. - * - * @return string - */ - public function getInterval() - { - return $this->interval; - } - - /** - * Gets intervalCount value. - * - * @return int - */ - public function getIntervalCount() - { - return $this->intervalCount; - } - - /** - * Gets price value. - * - * @return int - */ - public function getPrice() - { - return $this->price; - } - /** * Gets productDescription value. * diff --git a/src/Model/RecurringPayment/RequestCreateAgreementBase.php b/src/Model/RecurringPayment/RequestCreateAgreementBase.php new file mode 100644 index 0000000..8fe02dd --- /dev/null +++ b/src/Model/RecurringPayment/RequestCreateAgreementBase.php @@ -0,0 +1,13 @@ +orderId = $orderId; return $this; } + + /** + * Set the value of transactionType + * + * @param string $transactionType + * + * @return self + */ + public function setTransactionType(string $transactionType) + { + $this->transactionType = $transactionType; + + return $this; + } } diff --git a/src/Model/RecurringPayment/RequestUpdateAgreementBase.php b/src/Model/RecurringPayment/RequestUpdateAgreementBase.php new file mode 100644 index 0000000..ecb02a5 --- /dev/null +++ b/src/Model/RecurringPayment/RequestUpdateAgreementBase.php @@ -0,0 +1,13 @@ +agreementId; } + + /** + * Set the value of agreementId + * + * @param string $agreementId + * + * @return self + */ + public function setAgreementId(string $agreementId) + { + $this->agreementId = $agreementId; + + return $this; + } } diff --git a/src/Model/RecurringPayment/v2/Agreement.php b/src/Model/RecurringPayment/v2/Agreement.php new file mode 100644 index 0000000..d8eff37 --- /dev/null +++ b/src/Model/RecurringPayment/v2/Agreement.php @@ -0,0 +1,95 @@ +campaign; + } + + /** + * Gets currency value. + * + * @return string + */ + public function getCurrency() + { + return $this->currency; + } + + /** + * 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; + } +} diff --git a/src/Model/RecurringPayment/CampaignRequest.php b/src/Model/RecurringPayment/v2/CampaignRequest.php similarity index 95% rename from src/Model/RecurringPayment/CampaignRequest.php rename to src/Model/RecurringPayment/v2/CampaignRequest.php index 43e5f87..4937d2b 100644 --- a/src/Model/RecurringPayment/CampaignRequest.php +++ b/src/Model/RecurringPayment/v2/CampaignRequest.php @@ -1,6 +1,6 @@ initialCharge = $initialCharge; return $this; diff --git a/src/Model/RecurringPayment/RequestUpdateAgreement.php b/src/Model/RecurringPayment/v2/RequestUpdateAgreement.php similarity index 84% rename from src/Model/RecurringPayment/RequestUpdateAgreement.php rename to src/Model/RecurringPayment/v2/RequestUpdateAgreement.php index 79cf58d..5d1e6aa 100644 --- a/src/Model/RecurringPayment/RequestUpdateAgreement.php +++ b/src/Model/RecurringPayment/v2/RequestUpdateAgreement.php @@ -1,7 +1,8 @@ interval; + } + + /** + * Gets price value. + * + * @return \zaporylie\Vipps\Model\RecurringPayment\v3\Pricing + */ + public function getPricing() + { + return $this->pricing; + } + + /** + * Gets campaign value. + * + * @return \zaporylie\Vipps\Model\RecurringPayment\v3\CampaignRequest + */ + public function getCampaign() + { + return $this->campaign; + } +} diff --git a/src/Model/RecurringPayment/v3/Campaign/EventCampaign.php b/src/Model/RecurringPayment/v3/Campaign/EventCampaign.php new file mode 100644 index 0000000..6f59830 --- /dev/null +++ b/src/Model/RecurringPayment/v3/Campaign/EventCampaign.php @@ -0,0 +1,118 @@ +") + */ + protected $eventDate; + + /** + * @var string + * @Serializer\Type("string") + */ + protected $eventText; + + + /** + * Get the value of type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Get the value of campaignPrice + * + * @return int + */ + public function getPrice() + { + return $this->price; + } + + /** + * Set the value of campaignPrice + * + * @param int $campaignPrice + * + * @return self + */ + public function setPrice(int $price) + { + $this->price = $price; + + return $this; + } + + /** + * @return \DateTimeInterface + */ + public function getEventDate() + { + return $this->eventDate; + } + + /** + * @param \DateTimeInterface $eventDate + * + * @return self + */ + public function setEventDate($eventDate) + { + $this->eventDate = $eventDate; + + return $this; + } + + /** + * Get the value of eventText + * + * @return string + */ + public function getEventText() + { + return $this->eventText; + } + + /** + * Set the value of eventText + * + * @param string $eventText + * + * @return self + */ + public function setEventText(string $eventText) + { + $this->eventText = $eventText; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/Campaign/FullFlexCampaign.php b/src/Model/RecurringPayment/v3/Campaign/FullFlexCampaign.php new file mode 100644 index 0000000..b6ab643 --- /dev/null +++ b/src/Model/RecurringPayment/v3/Campaign/FullFlexCampaign.php @@ -0,0 +1,122 @@ +") + */ + protected $end; + + + /** + * Get the value of end + * + * @return \DateTimeInterface + */ + public function getEnd() + { + return $this->end; + } + + /** + * Get the value of campaignPrice + * + * @return int + */ + public function getPrice() + { + return $this->price; + } + + /** + * Set the value of campaignPrice + * + * @param int $campaignPrice + * + * @return self + */ + public function setPrice(int $price) + { + $this->price = $price; + + return $this; + } + + /** + * Get the value of interval + * + * @return \zaporylie\Vipps\Model\RecurringPayment\v3\Period + */ + public function getInterval() + { + return $this->interval; + } + + /** + * Set the value of interval + * + * @param \zaporylie\Vipps\Model\RecurringPayment\v3\Period $interval + * + * @return self + */ + public function setInterval(\zaporylie\Vipps\Model\RecurringPayment\v3\Period $interval) + { + $this->interval = $interval; + + return $this; + } + + /** + * Get the value of type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set the value of end + * + * @param \DateTimeInterface $end + * + * @return self + */ + public function setEnd(\DateTimeInterface $end) + { + $this->end = $end; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/Campaign/PeriodCampaign.php b/src/Model/RecurringPayment/v3/Campaign/PeriodCampaign.php new file mode 100644 index 0000000..6b3d32e --- /dev/null +++ b/src/Model/RecurringPayment/v3/Campaign/PeriodCampaign.php @@ -0,0 +1,88 @@ +type; + } + + /** + * Get the value of campaignPrice + * + * @return int + */ + public function getPrice() + { + return $this->price; + } + + /** + * Set the value of campaignPrice + * + * @param int $campaignPrice + * + * @return self + */ + public function setPrice(int $price) + { + $this->price = $price; + + return $this; + } + + /** + * @return \zaporylie\Vipps\Model\RecurringPayment\v3\Period + */ + public function getPeriod() + { + return $this->period; + } + + /** + * @param \zaporylie\Vipps\Model\RecurringPayment\v3\Period $period + * + * @return self + */ + public function setPeriod(\zaporylie\Vipps\Model\RecurringPayment\v3\Period $period) + { + $this->period = $period; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/Campaign/PriceCampaign.php b/src/Model/RecurringPayment/v3/Campaign/PriceCampaign.php new file mode 100644 index 0000000..6f1f71d --- /dev/null +++ b/src/Model/RecurringPayment/v3/Campaign/PriceCampaign.php @@ -0,0 +1,92 @@ +") + */ + protected $end; + + + /** + * Get the value of type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Get the value of campaignPrice + * + * @return int + */ + public function getPrice() + { + return $this->price; + } + + /** + * Set the value of campaignPrice + * + * @param int $campaignPrice + * + * @return self + */ + public function setPrice(int $price) + { + $this->price = $price; + + return $this; + } + + /** + * Get the value of end + * + * @return \DateTimeInterface + */ + public function getEnd() + { + return $this->end; + } + + /** + * Set the value of end + * + * @param \DateTimeInterface $end + * + * @return self + */ + public function setEnd(\DateTimeInterface $end) + { + $this->end = $end; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/CampaignRequest.php b/src/Model/RecurringPayment/v3/CampaignRequest.php new file mode 100644 index 0000000..25a966c --- /dev/null +++ b/src/Model/RecurringPayment/v3/CampaignRequest.php @@ -0,0 +1,186 @@ +") + */ + protected $end; + + /** + * Only required for type eventCampaignV3 + * @var \DateTimeInterface + * @Serializer\Type("DateTime<'Y-m-d\TH:i:s\Z'>") + */ + protected $eventDate; + + /** + * Get the value of end + * + * @return \DateTimeInterface + */ + public function getEnd() + { + return $this->end; + } + + /** + * Set the value of end + * + * @param \DateTimeInterface $end + * + * @return self + */ + public function setEnd(\DateTimeInterface $end) + { + $this->end = $end; + + return $this; + } + + /** + * Get the value of campaignPrice + * + * @return int + */ + public function getPrice() + { + return $this->price; + } + + /** + * Set the value of campaignPrice + * + * @param int $campaignPrice + * + * @return self + */ + public function setPrice(int $price) + { + $this->price = $price; + + return $this; + } + + /** + * Get the value of interval + * + * @return Period + */ + public function getInterval() + { + return $this->interval; + } + + /** + * Set the value of interval + * + * @param Period $interval + * + * @return self + */ + public function setInterval(Period $interval) + { + $this->interval = $interval; + + return $this; + } + + /** + * @return Period + */ + public function getPeriod() + { + return $this->period; + } + + /** + * @param Period $period Only required for type periodChampaignV3 + * + * @return self + */ + public function setPeriod(Period $period) + { + $this->period = $period; + + return $this; + } + + /** + * @return \DateTimeInterface + */ + public function getEventDate() + { + return $this->eventDate; + } + + /** + * @param \DateTimeInterface $eventDate + * + * @return self + */ + public function setEventDate($eventDate) + { + $this->eventDate = $eventDate; + + return $this; + } + + /** + * Get the value of type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set the value of type + * + * @param string $type + * + * @return self + */ + public function setType(string $type) + { + $this->type = $type; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/CampaignType.php b/src/Model/RecurringPayment/v3/CampaignType.php new file mode 100644 index 0000000..62fd398 --- /dev/null +++ b/src/Model/RecurringPayment/v3/CampaignType.php @@ -0,0 +1,21 @@ +unit = $unit; + return $this; + } + + /** + * Sets count variable. + * + * @param int $count + * + * @return $this + */ + public function setCount($count) + { + $this->count = $count; + return $this; + } + +} diff --git a/src/Model/RecurringPayment/v3/Pricing.php b/src/Model/RecurringPayment/v3/Pricing.php new file mode 100644 index 0000000..1dde136 --- /dev/null +++ b/src/Model/RecurringPayment/v3/Pricing.php @@ -0,0 +1,91 @@ +type = $type; + return $this; + } + + /** + * 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; + } + + + /** + * Set the value of suggestedMaxAmount + * + * @param int $suggestedMaxAmount + * + * @return self + */ + public function setSuggestedMaxAmount($suggestedMaxAmount) + { + $this->suggestedMaxAmount = $suggestedMaxAmount; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/PricingType.php b/src/Model/RecurringPayment/v3/PricingType.php new file mode 100644 index 0000000..2ecd8fe --- /dev/null +++ b/src/Model/RecurringPayment/v3/PricingType.php @@ -0,0 +1,19 @@ +amount; + } + + /** + * Set the value of amount + * + * @param int $amount + * + * @return self + */ + public function setAmount(int $amount) + { + $this->amount = $amount; + + return $this; + } + + /** + * Get the value of description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set the value of description + * + * @param string $description + * + * @return self + */ + public function setDescription(string $description) + { + $this->description = $description; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/RequestCreateAgreement.php b/src/Model/RecurringPayment/v3/RequestCreateAgreement.php new file mode 100644 index 0000000..8bda58d --- /dev/null +++ b/src/Model/RecurringPayment/v3/RequestCreateAgreement.php @@ -0,0 +1,286 @@ +campaign = $campaign; + return $this; + } + + /** + * Set the value of pricing + * + * @param \zaporylie\Vipps\Model\RecurringPayment\v3\Pricing $pricing + * + * @return self + */ + public function setPricing(\zaporylie\Vipps\Model\RecurringPayment\v3\Pricing $pricing) + { + $this->pricing = $pricing; + return $this; + } + + /** + * Sets phoneNumber variable. + * + * @param string $phoneNumber + * + * @return $this + */ + public function setPhoneNumber($phoneNumber) + { + $this->phoneNumber = $phoneNumber; + return $this; + } + + /** + * Sets initialCharge variable. + * + * @param \zaporylie\Vipps\Model\RecurringPayment\InitialCharge $initialCharge + * + * @return $this + */ + public function setInitialCharge(\zaporylie\Vipps\Model\RecurringPayment\InitialCharge $initialCharge) + { + $this->initialCharge = $initialCharge; + return $this; + } + + /** + * Sets interval variable. + * + * @param \zaporylie\Vipps\Model\RecurringPayment\v3\Period $interval + * + * @return $this + */ + public function setInterval(\zaporylie\Vipps\Model\RecurringPayment\v3\Period $interval) + { + $this->interval = $interval; + 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 productName variable. + * + * @param string $productName + * + * @return $this + */ + public function setProductName($productName) + { + $this->productName = $productName; + return $this; + } + + /** + * Sets productDescription variable. + * + * @param string $productDescription + * + * @return $this + */ + public function setProductDescription($productDescription) + { + $this->productDescription = $productDescription; + return $this; + } + + + /** + * Sets scope variable. + * + * @param string $scope + * + * @return $this + */ + public function setScope($scope) + { + $this->scope = $scope; + return $this; + } + + /** + * Set the value of skipLandingPage + * + * @param bool $skipLandingPage + * + * @return self + */ + public function setSkipLandingPage($skipLandingPage) + { + $this->skipLandingPage = $skipLandingPage; + + return $this; + } + + /** + * Set the value of externalId + * + * @param string $externalId + * + * @return self + */ + public function setExternalId($externalId) + { + $this->externalId = $externalId; + + return $this; + } + + /** + * Set the value of countryCode + * + * @param string $countryCode + * + * @return self + */ + public function setCountryCode($countryCode) + { + $this->countryCode = $countryCode; + + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/RequestUpdateAgreement.php b/src/Model/RecurringPayment/v3/RequestUpdateAgreement.php new file mode 100644 index 0000000..8d2f910 --- /dev/null +++ b/src/Model/RecurringPayment/v3/RequestUpdateAgreement.php @@ -0,0 +1,130 @@ +productName = $productName; + return $this; + } + + /** + * Sets productDescription variable. + * + * @param string $productDescription + * + * @return $this + */ + public function setProductDescription($productDescription) + { + $this->productDescription = $productDescription; + return $this; + } + + /** + * Sets merchantAgreementUrl variable. + * + * @param string $merchantAgreementUrl + * + * @return $this + */ + public function setMerchantAgreementUrl($merchantAgreementUrl) + { + $this->merchantAgreementUrl = $merchantAgreementUrl; + return $this; + } + + /** + * Set the value of externalId + * + * @param string $externalId + * + * @return self + */ + public function setExternalId($externalId) + { + $this->externalId = $externalId; + + return $this; + } + + /** + * Sets status variable. + * + * @param string $status + * + * @return $this + */ + public function setStatus($status) + { + $this->status = $status; + return $this; + } + + /** + * Set the value of pricing + * + * @param \zaporylie\Vipps\Model\RecurringPayment\v3\Pricing $pricing + * + * @return self + */ + public function setPricing(\zaporylie\Vipps\Model\RecurringPayment\v3\Pricing $pricing) + { + $this->pricing = $pricing; + return $this; + } +} diff --git a/src/Model/RecurringPayment/v3/ResponseGetAgreement.php b/src/Model/RecurringPayment/v3/ResponseGetAgreement.php new file mode 100644 index 0000000..4574916 --- /dev/null +++ b/src/Model/RecurringPayment/v3/ResponseGetAgreement.php @@ -0,0 +1,15 @@ +id = $agreement_id; $this->charge_id = $charge_id; - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); } /** diff --git a/src/Resource/RecurringPayment/CaptureCharge.php b/src/Resource/RecurringPayment/CaptureCharge.php index cdc536b..d66b8c3 100644 --- a/src/Resource/RecurringPayment/CaptureCharge.php +++ b/src/Resource/RecurringPayment/CaptureCharge.php @@ -5,6 +5,7 @@ use zaporylie\Vipps\Model\RecurringPayment\RequestCreateCharge; use zaporylie\Vipps\Model\RecurringPayment\ResponseCaptureCharge; use zaporylie\Vipps\Model\RecurringPayment\ResponseCreateCharge; +use zaporylie\Vipps\Model\RecurringPayment\v3\RequestCaptureCharge; use zaporylie\Vipps\Resource\HttpMethod; use zaporylie\Vipps\Resource\IdempotencyKeyFactory; use zaporylie\Vipps\Resource\RequestIdFactory; @@ -26,7 +27,7 @@ class CaptureCharge extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}/charges/{charge_id}/capture'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}/charges/{charge_id}/capture'; /** * InitiatePayment constructor. @@ -38,15 +39,21 @@ class CaptureCharge extends RecurringPaymentResourceBase */ public function __construct( VippsInterface $vipps, + $api_endpoint_version, $subscription_key, $agreement_id, - $charge_id + $charge_id, + RequestCaptureCharge $requestObject ) { $this->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); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); + $this->body = $this + ->getSerializer() + ->serialize( + $requestObject, + 'json' + ); } /** diff --git a/src/Resource/RecurringPayment/CreateAgreement.php b/src/Resource/RecurringPayment/CreateAgreement.php index ed05aee..f8e1acd 100644 --- a/src/Resource/RecurringPayment/CreateAgreement.php +++ b/src/Resource/RecurringPayment/CreateAgreement.php @@ -2,9 +2,9 @@ namespace zaporylie\Vipps\Resource\RecurringPayment; -use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement; -use zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase; use zaporylie\Vipps\Resource\HttpMethod; +use zaporylie\Vipps\Resource\IdempotencyKeyFactory; use zaporylie\Vipps\VippsInterface; /** @@ -23,18 +23,18 @@ class CreateAgreement extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements'; + protected $path = '/recurring/v{api_endpoint_version}/agreements'; /** * InitiatePayment constructor. * * @param \zaporylie\Vipps\VippsInterface $vipps * @param string $subscription_key - * @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreement $requestObject + * @param \zaporylie\Vipps\Model\RecurringPayment\RequestCreateAgreementBase $requestObject */ - public function __construct(VippsInterface $vipps, $subscription_key, RequestCreateAgreement $requestObject) + public function __construct(VippsInterface $vipps, $api_endpoint_version, $subscription_key, RequestCreateAgreementBase $requestObject) { - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->body = $this ->getSerializer() ->serialize( @@ -55,7 +55,7 @@ public function call() ->getSerializer() ->deserialize( $body, - ResponseCreateAgreement::class, + \zaporylie\Vipps\Model\RecurringPayment\ResponseCreateAgreement::class, 'json' ); diff --git a/src/Resource/RecurringPayment/CreateCharge.php b/src/Resource/RecurringPayment/CreateCharge.php index e86bcec..729d3e8 100644 --- a/src/Resource/RecurringPayment/CreateCharge.php +++ b/src/Resource/RecurringPayment/CreateCharge.php @@ -25,7 +25,7 @@ class CreateCharge extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}/charges'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}/charges'; /** * InitiatePayment constructor. @@ -37,14 +37,13 @@ class CreateCharge extends RecurringPaymentResourceBase */ public function __construct( VippsInterface $vipps, + $api_endpoint_version, $subscription_key, $agreementId, RequestCreateCharge $requestObject ) { $this->id = $agreementId; - // By default RequestID is different for each Resource object. - $this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate(); - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->body = $this ->getSerializer() ->serialize( diff --git a/src/Resource/RecurringPayment/GetAgreement.php b/src/Resource/RecurringPayment/GetAgreement.php index 8333028..d710745 100644 --- a/src/Resource/RecurringPayment/GetAgreement.php +++ b/src/Resource/RecurringPayment/GetAgreement.php @@ -2,7 +2,9 @@ namespace zaporylie\Vipps\Resource\RecurringPayment; -use zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement; +use zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase; +use zaporylie\Vipps\Model\RecurringPayment\v2\ResponseGetAgreement as ResponseGetAgreementV2; +use zaporylie\Vipps\Model\RecurringPayment\v3\ResponseGetAgreement as ResponseGetAgreementV3; use zaporylie\Vipps\Resource\HttpMethod; use zaporylie\Vipps\VippsInterface; @@ -22,7 +24,7 @@ class GetAgreement extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}'; /** * InitiatePayment constructor. @@ -31,25 +33,26 @@ class GetAgreement extends RecurringPaymentResourceBase * @param string $subscription_key * @param $agreement_id */ - public function __construct(VippsInterface $vipps, $subscription_key, $agreement_id) + public function __construct(VippsInterface $vipps, $api_endpoint_version, $subscription_key, $agreement_id) { - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->id = $agreement_id; } /** - * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement + * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase */ public function call() { $response = $this->makeCall(); $body = $response->getBody()->getContents(); - /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement $responseObject */ + /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreementBase $responseObject */ $responseObject = $this ->getSerializer() ->deserialize( $body, - ResponseGetAgreement::class, + //Not a good way to go about version management + $this->api_endpoint_version == 3 ? ResponseGetAgreementV3::class : ResponseGetAgreementV2::class, 'json' ); diff --git a/src/Resource/RecurringPayment/GetAgreements.php b/src/Resource/RecurringPayment/GetAgreements.php index 0d6a559..4072bbb 100644 --- a/src/Resource/RecurringPayment/GetAgreements.php +++ b/src/Resource/RecurringPayment/GetAgreements.php @@ -3,6 +3,8 @@ namespace zaporylie\Vipps\Resource\RecurringPayment; use zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement; +use zaporylie\Vipps\Model\RecurringPayment\v2\ResponseGetAgreement as ResponseGetAgreementV2; +use zaporylie\Vipps\Model\RecurringPayment\v3\ResponseGetAgreement as ResponseGetAgreementV3; use zaporylie\Vipps\Resource\HttpMethod; /** @@ -21,7 +23,7 @@ class GetAgreements extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements'; + protected $path = '/recurring/v{api_endpoint_version}/agreements'; /** * @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[] @@ -35,7 +37,8 @@ public function call() ->getSerializer() ->deserialize( $body, - sprintf("array<%s>", ResponseGetAgreement::class), + //Not a good way to go about version management + sprintf("array<%s>", $this->api_endpoint_version == 3 ? ResponseGetAgreementV3::class : ResponseGetAgreementV2::class), 'json' ); diff --git a/src/Resource/RecurringPayment/GetCharge.php b/src/Resource/RecurringPayment/GetCharge.php index 3029f10..bb8aec9 100644 --- a/src/Resource/RecurringPayment/GetCharge.php +++ b/src/Resource/RecurringPayment/GetCharge.php @@ -21,15 +21,16 @@ class GetCharge extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}/charges/{charge_id}'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}/charges/{charge_id}'; public function __construct( \zaporylie\Vipps\VippsInterface $vipps, + $api_endpoint_version, $subscription_key, $agreement_id, $charge_id ) { - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->id = $agreement_id; $this->charge_id = $charge_id; } diff --git a/src/Resource/RecurringPayment/GetCharges.php b/src/Resource/RecurringPayment/GetCharges.php index 541b99e..4d2f07a 100644 --- a/src/Resource/RecurringPayment/GetCharges.php +++ b/src/Resource/RecurringPayment/GetCharges.php @@ -21,14 +21,15 @@ class GetCharges extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}/charges'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}/charges'; public function __construct( \zaporylie\Vipps\VippsInterface $vipps, + $api_endpoint_version, $subscription_key, $agreement_id ) { - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->id = $agreement_id; } diff --git a/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php b/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php index 7af5980..14156b7 100644 --- a/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php +++ b/src/Resource/RecurringPayment/RecurringPaymentResourceBase.php @@ -6,6 +6,7 @@ use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; use JMS\Serializer\SerializerBuilder; use zaporylie\Vipps\Resource\AuthorizedResourceBase; +use zaporylie\Vipps\Resource\IdempotencyKeyFactory; use zaporylie\Vipps\Resource\RequestIdFactory; /** @@ -21,12 +22,18 @@ abstract class RecurringPaymentResourceBase extends AuthorizedResourceBase */ protected $charge_id; + /** + * @var int + */ + protected $api_endpoint_version; + /** * {@inheritdoc} */ - public function __construct(\zaporylie\Vipps\VippsInterface $vipps, $subscription_key) + public function __construct(\zaporylie\Vipps\VippsInterface $vipps, $api_endpoint_version, $subscription_key) { parent::__construct($vipps, $subscription_key); + $this->api_endpoint_version = $api_endpoint_version; // Adjust serializer. $this->serializer = SerializerBuilder::create() @@ -41,20 +48,28 @@ public function __construct(\zaporylie\Vipps\VippsInterface $vipps, $subscriptio // Timestamp is equal to current DateTime. $this->headers['X-TimeStamp'] = (new \DateTime())->format(\DateTime::ISO8601); + + $this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate(); } /** * {@inheritdoc} * - * All occurrences of {id} pattern will be replaced with $this->id + * All occurrences of {charge_id} pattern will be replaced with $this->id + * All occurrances of {api_endpoint_version} will be replaced by $this->api_endpoint_version */ public function getPath() { $path = parent::getPath(); - // If ID is set replace {id} pattern with model's ID. + // If charge_id is set replace {charge_id} pattern with model's charge_id. if (isset($this->charge_id)) { - $path = str_replace('{charge_id}', $this->charge_id, $path); + $path = str_replace('{charge_id}', strval($this->charge_id), $path); + } + + //If API Endpoint is set replace {api_endpoint_version} pattern with + if (isset($this->api_endpoint_version)) { + $path = str_replace('{api_endpoint_version}', $this->api_endpoint_version, $path); } return $path; } diff --git a/src/Resource/RecurringPayment/RefundCharge.php b/src/Resource/RecurringPayment/RefundCharge.php index 6bdcb3b..7b241ad 100644 --- a/src/Resource/RecurringPayment/RefundCharge.php +++ b/src/Resource/RecurringPayment/RefundCharge.php @@ -27,7 +27,7 @@ class RefundCharge extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}/charges/{charge_id}/refund'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}/charges/{charge_id}/refund'; /** * RefundCharge constructor. @@ -40,6 +40,7 @@ class RefundCharge extends RecurringPaymentResourceBase */ public function __construct( VippsInterface $vipps, + $api_endpoint_version, $subscription_key, $agreement_id, $charge_id, @@ -47,9 +48,8 @@ public function __construct( ) { $this->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); + + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->body = $this ->getSerializer() ->serialize( diff --git a/src/Resource/RecurringPayment/UpdateAgreement.php b/src/Resource/RecurringPayment/UpdateAgreement.php index b9c0133..71a8ea4 100644 --- a/src/Resource/RecurringPayment/UpdateAgreement.php +++ b/src/Resource/RecurringPayment/UpdateAgreement.php @@ -2,7 +2,7 @@ namespace zaporylie\Vipps\Resource\RecurringPayment; -use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreement; +use zaporylie\Vipps\Model\RecurringPayment\RequestUpdateAgreementBase; use zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement; use zaporylie\Vipps\Resource\HttpMethod; use zaporylie\Vipps\VippsInterface; @@ -23,7 +23,7 @@ class UpdateAgreement extends RecurringPaymentResourceBase /** * @var string */ - protected $path = '/recurring/v2/agreements/{id}'; + protected $path = '/recurring/v{api_endpoint_version}/agreements/{id}'; /** * InitiatePayment constructor. @@ -35,11 +35,12 @@ class UpdateAgreement extends RecurringPaymentResourceBase */ public function __construct( VippsInterface $vipps, + $api_endpoint_version, $subscription_key, $agreement_id, - RequestUpdateAgreement $requestObject + RequestUpdateAgreementBase $requestObject ) { - parent::__construct($vipps, $subscription_key); + parent::__construct($vipps, $api_endpoint_version, $subscription_key); $this->id = $agreement_id; $this->body = $this ->getSerializer() @@ -57,14 +58,19 @@ public function call() $response = $this->makeCall(); $body = $response->getBody()->getContents(); /** @var \zaporylie\Vipps\Model\RecurringPayment\ResponseUpdateAgreement $responseObject */ - $responseObject = $this + + if ($this->api_endpoint_version > 2) { + $responseObject = new ResponseUpdateAgreement(); + $responseObject->setAgreementId($this->id); + } else { + $responseObject = $this ->getSerializer() ->deserialize( $body, ResponseUpdateAgreement::class, 'json' ); - + } return $responseObject; } } diff --git a/src/Resource/ResourceBase.php b/src/Resource/ResourceBase.php index 0ceedf6..53703bc 100644 --- a/src/Resource/ResourceBase.php +++ b/src/Resource/ResourceBase.php @@ -68,7 +68,6 @@ abstract class ResourceBase implements ResourceInterface, SerializableInterface public function __construct(VippsInterface $vipps, $subscription_key) { $this->app = $vipps; - $this->headers['Ocp-Apim-Subscription-Key'] = $subscription_key; // Initiate serializer. diff --git a/src/Vipps.php b/src/Vipps.php index 98f6fb5..f30e817 100644 --- a/src/Vipps.php +++ b/src/Vipps.php @@ -58,12 +58,13 @@ public function payment($subscription_key, $merchant_serial_number, $custom_path /** * @param string $subscription_key * @param string $merchant_serial_number + * @param int $api_endpoint_version * * @return \zaporylie\Vipps\Api\RecurringPaymentInterface */ - public function recurringPayment($subscription_key, $merchant_serial_number) + public function recurringPayment($subscription_key, $merchant_serial_number, $api_endpoint_version = 3) { - return new RecurringPayment($this, $subscription_key, $merchant_serial_number); + return new RecurringPayment($this, $subscription_key, $merchant_serial_number, $api_endpoint_version); } /** diff --git a/src/VippsInterface.php b/src/VippsInterface.php index 60ec7d5..ecfe2a7 100644 --- a/src/VippsInterface.php +++ b/src/VippsInterface.php @@ -39,8 +39,9 @@ public function payment($subscription_key, $merchant_serial_number, $custom_path /** * @param string $subscription_key * @param string $merchant_serial_number + * @param int $api_endpoint_version * * @return \zaporylie\Vipps\Api\RecurringPaymentInterface */ - public function recurringPayment($subscription_key, $merchant_serial_number); + public function recurringPayment($subscription_key, $merchant_serial_number, $api_endpoint_version = 3); }