Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sc-57428): Support Opportunities API #124

Conversation

kamilpavlicko
Copy link
Contributor

closes ticket: https://app.shortcut.com/chartmogul/story/57428/support-opportunities-resource-php-client

API Specs: https://www.notion.so/chartmogul/API-endpoints-for-Opportunities-a92323514bf44f89ad2f97ae30cee7f0#6f09cc7a71bc40e69ef65d8d0342d230

Customers

List Opportunities from a customer

$customer = ChartMogul\Customer::retrieve($uuid);
$opportunities = $customer->opportunities([
  'cursor' => 'aabbccdd...'
]);

Create an Opportunity from a customer

$customer = ChartMogul\Customer::retrieve($uuid);
$new_opportunity = $customer->createOpportunity([
  'owner' => '[email protected]',
  'pipeline' => 'Sales',
  'pipeline_stage' => 'Qualified',
  'estimated_close_date' => '2022-03-30',
  'currency' => 'USD',
  'amount_in_cents' => 10000,
  'type' => 'one-time',
  'forecast_category' => 'Best Case',
  'win_likelihood' => 80,
  'custom' => [{key: 'custom_key', value: 'custom_value'}]
]);

Opportunities

List Opportunities

$opportunities = ChartMogul\Opportunity::all([
    'cursor' => 'aabbccdd...'
])

Create an Opportunity

$opportunity = ChartMogul\Opportunity::create([
    'customer_uuid' => $uuid,
    'owner' => '[email protected]',
    'pipeline' => 'New business 1',
    'pipeline_stage' => 'Discovery',
    'estimated_close_date' => '2023-12-22',
    'currency' => 'USD',
    'amount_in_cents' => 100,
    'type' => 'recurring',
    'forecast_category' => 'pipeline',
    'win_likelihood' => 3,
    'custom' => [{ 'key': 'from_campaign', 'value': 'true' }]
])

Get an Opportunity

$opportunity = ChartMogul\Opportunity::retrieve($opportunity_uuid)

Update an Opportunity

$updated_opportunity = ChartMogul\Opportunity::update($opportunity_uuid, [
  'estimated_close_date' => '2024-12-22',
]);

Delete an Opportunity

$opportunity = ChartMogul\Opportunity::retrieve($opportunity_uuid)
$opportunity->destroy();

@kamilpavlicko kamilpavlicko self-assigned this Mar 21, 2024
Copy link

This pull request has been linked to Shortcut Story #57428: Support Opportunities resource - PHP client.

Copy link
Contributor

@SoeunSona SoeunSona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and I left a question

"type": "recurring",
"forecast_category": "pipeline",
"win_likelihood": 3,
"custom": {"from_campaign": true},
Copy link
Contributor

@SoeunSona SoeunSona Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think custom type is array in here but this type is object Ah please ignore this comment. I checked the api document

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch, but the data should be correct now 😊
I just added a new test for creating the opportunity from customer.

Copy link

codeclimate bot commented Mar 22, 2024

Code Climate has analyzed commit caad9bf and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 75.6%.

View more on Code Climate.

@kamilpavlicko kamilpavlicko merged commit 40668bd into main Mar 25, 2024
8 checks passed
@kamilpavlicko kamilpavlicko deleted the kamilpavlicko/feat/sc-57428/support-opportunities-resource-php-client branch March 25, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants