Skip to content

Commit

Permalink
Added updating of subscription quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdgeijn committed Jan 13, 2023
1 parent 8f072d8 commit ebee738
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Requests/OrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function get(string $orderId): ?Order
* @return mixed|null
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function create(\stdClass $options)
public function create(\stdClass $options, $isMock = false ): mixed
{
$response = $this->postRequest('/v1/orders', $options );
$response = $this->postRequest('/v1/orders' . ( $isMock ? "?isMock=1" : "" ), $options );

if ($response->getStatusCode() == 200)
return json_decode($response->getBody());
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/SubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ public function get(string $subscriptionId ): ?Subscription
else
return null;
}

public function update( string $subscriptionId, int $quantity ): ?Subscription
{
$data = new \stdClass();
$data->quantity = $quantity;
$data->startdate = date("Y-m-d");
$data->billingTerm = "Monthly";

$response = $this->putRequest('/v1/subscriptions/' . $subscriptionId, $data );

if ($response->getStatusCode() == 200)
return Subscription::parse(json_decode( $response->getBody() ) );
else
return null;
}
}
50 changes: 44 additions & 6 deletions src/Responses/OrderLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

class OrderLine extends AbstractResponse
{
protected string $productId;
public string $productId;

protected string $subscriptionId;
public string $subscriptionId;

protected Carbon $provisionStartDate;
public Carbon $provisionStartDate;

protected string $billingTerm;
public array $provisioningDetails;

protected int $quantity;
public string $billingTerm;

public string $commitmentTermId;

public int $quantity;

/**
* @param string $productId
Expand Down Expand Up @@ -67,7 +71,7 @@ public function setProvisionStartDate(Carbon $provisionStartDate): OrderLine
*/
public function getProvisionStartDate(): Carbon
{
return $this->provisionStartDate;
return $this->provisionStartDate->toDateString();
}

/**
Expand All @@ -88,6 +92,24 @@ public function getBillingTerm(): string
return $this->billingTerm;
}

/**
* @param string $commitmentTermId
* @return $this
*/
public function setCommitmentTermId(string $commitmentTermId): OrderLine
{
$this->commitmentTermId = $commitmentTermId;
return $this;
}

/**
* @return string
*/
public function getCommitmentTermId(): string
{
return $this->commitmentTermId;
}

/**
* @param int $quantity
* @return OrderLine
Expand All @@ -105,4 +127,20 @@ public function getQuantity(): int
{
return $this->quantity;
}

/**
* @param string $key
* @param string|array $values
* @return $this
*/
public function add(string $key, string|array $values ): OrderLine
{
$line = new \stdClass();
$line->key = $key;
$line->values = is_string( $values ) ? [$values] : $values;

$this->provisioningDetails[] = $line;

return $this;
}
}

0 comments on commit ebee738

Please sign in to comment.