Skip to content

Commit

Permalink
Added method for Connect subscriptions (#43)
Browse files Browse the repository at this point in the history
* Added method for Connect subscriptions

* fixed return type in docblock
  • Loading branch information
hassansin authored and pkopac committed Dec 20, 2018
1 parent e1107e2 commit eb4eb32
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ $result = ChartMogul\Customer::update([
]);
```

**Connect Subscriptions**

```php
ChartMogul\Customer::connectSubscriptions("cus_5915ee5a-babd-406b-b8ce-d207133fb4cb", [
"subscriptions" => [
[
"data_source_uuid" => "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id" => "d1c0c885-add0-48db-8fa9-0bdf5017d6b0",
],
[
"data_source_uuid" => "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id" => "9db5f4a1-1695-44c0-8bd4-de7ce4d0f1d4",
],
]
]);
```

#### Customer Attributes

Expand Down
16 changes: 16 additions & 0 deletions src/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ public static function merge($from, $into, ClientInterface $client = null)
return true;
}

/**
* Connect Subscriptions
* @param string $customerUUID
* @param array $data
* @param ClientInterface|null $client
* @return bool
*/
public static function connectSubscriptions($customerUUID, array $data = [], ClientInterface $client = null)
{
(new static([], $client))
->getClient()
->setResourcekey(static::class)
->send('/v1/customers/'.$customerUUID.'/connect_subscriptions', 'POST', $data);
return true;
}


/**
* Add tags to a customer
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,33 @@ public function testSearchCustomer(){
$this->assertEquals($result->page, 1);
$this->assertEquals($result->per_page, 200);
}
public function testConnectSubscriptions()
{
$stream = Psr7\stream_for('{}');
$response = new Response(202, ['Content-Type' => 'application/json'], $stream);
$mockClient = new \Http\Mock\Client();
$mockClient->addResponse($response);

$cmClient = new Client(null, $mockClient);
$result = Customer::connectSubscriptions("cus_5915ee5a-babd-406b-b8ce-d207133fb4cb", [
"subscriptions" => [
[
"data_source_uuid" => "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id" => "d1c0c885-add0-48db-8fa9-0bdf5017d6b0",
],
[
"data_source_uuid" => "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id" => "9db5f4a1-1695-44c0-8bd4-de7ce4d0f1d4",
],
]
], $cmClient);
$request = $mockClient->getRequests()[0];

$this->assertEquals("POST", $request->getMethod());
$uri = $request->getUri();
$this->assertEquals("", $uri->getQuery());
$this->assertEquals("/v1/customers/cus_5915ee5a-babd-406b-b8ce-d207133fb4cb/connect_subscriptions", $uri->getPath());

$this->assertEquals($result, true);
}
}

0 comments on commit eb4eb32

Please sign in to comment.