Skip to content

Commit

Permalink
[sc-62678] SDK Unmerge Support - PHP (#130)
Browse files Browse the repository at this point in the history
* Add support for unmerge endpoint.

* Update docs.
  • Loading branch information
jessicahearn authored Oct 24, 2024
1 parent fd0f489 commit 2a10ae3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ ChartMogul\Customer::merge([
]);
```

**Unmerge Customers**

```php
ChartMogul\Customer::unmerge(
$cus->uuid,
$cus->external_id,
$ds->uuid,
["tasks", "opportunities", "notes"]
);
```

**Update a Customer**

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

/**
* Unmerge Customers
*
* @param string $customer_uuid
* @param string $external_id
* @param string $data_source_uuid
* @param array $move_to_new_customer
* @param ClientInterface|null $client
* @return bool
*/
public static function unmerge($customer_uuid, $external_id, $data_source_uuid, array $move_to_new_customer = [], ClientInterface $client = null)
{
(new static([], $client))
->getClient()
->setResourcekey(static::class)
->send(
'/v1/customers/unmerges',
'POST',
[
'customer_uuid' => $customer_uuid,
'external_id' => $external_id,
'data_source_uuid' => $data_source_uuid,
'move_to_new_customer' => $move_to_new_customer
]
);
return true;
}

/**
* Connect Subscriptions
*
Expand Down
40 changes: 40 additions & 0 deletions tests/Unit/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,46 @@ public function testSearchCustomer()
$this->assertEquals($result->cursor, "cursor==");
}

public function testMergeCustomers()
{
$stream = Psr7\stream_for('{}');
list($cmClient, $mockClient) = $this->getMockClient(0, [200], $stream);

$from_customer_uuid = "cus_de305d54-75b4-431b-adb2-eb6b9e546012";
$into_customer_uuid = "cus_ab223d54-75b4-431b-adb2-eb6b9e234571";

$result = Customer::merge($from_customer_uuid, $into_customer_uuid, $cmClient);
$request = $mockClient->getRequests()[0];

$this->assertEquals("POST", $request->getMethod());
$uri = $request->getUri();
$this->assertEquals("", $uri->getQuery());
$this->assertEquals("/v1/customers/merges", $uri->getPath());

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

public function testUnmergeCustomers()
{
$stream = Psr7\stream_for('{}');
list($cmClient, $mockClient) = $this->getMockClient(0, [200], $stream);

$customer_uuid = "cus_cd9e5f29-6299-40e5-b343-0bd1ed228b4f";
$external_id = "cus_O075O8NH0LrtG8";
$data_source_uuid = "ds_788ec6ae-dd51-11ee-bd46-a3ec952dc041";
$move_to_new_customer = [];

$result = Customer::unmerge($customer_uuid, $external_id, $data_source_uuid, $move_to_new_customer, $cmClient);
$request = $mockClient->getRequests()[0];

$this->assertEquals("POST", $request->getMethod());
$uri = $request->getUri();
$this->assertEquals("", $uri->getQuery());
$this->assertEquals("/v1/customers/unmerges", $uri->getPath());

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

public function testConnectSubscriptions()
{
$stream = Psr7\stream_for('{}');
Expand Down

0 comments on commit 2a10ae3

Please sign in to comment.