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

Shopify integration #173

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
9ac9680
Removed previous Shopify logic
bohdan-vorona Feb 21, 2023
1b54cc4
E-commerce Platforms
bohdan-vorona Feb 22, 2023
7ca9f6a
Ecommerce Integrations
bohdan-vorona Feb 23, 2023
6716abb
Update console/migrations/m230221_134343_add_shopify_mock_ecommerce_p…
bohdan-vorona Feb 24, 2023
c7efa45
Update m230221_134343_add_shopify_mock_ecommerce_platfort.php
bohdan-vorona Feb 24, 2023
09104d5
Shopify OAuth implementation
bohdan-vorona Feb 25, 2023
770e859
Some changes in the logic + actions {disconnect/pause/resume}
bohdan-vorona Feb 27, 2023
d1a56eb
Shopify documentation
bohdan-vorona Feb 27, 2023
11d73ba
Connected shops
bohdan-vorona Feb 27, 2023
0e1338a
Update
bohdan-vorona Mar 2, 2023
14fa575
Added: Order Statuses, Financial Statuses, Fulfillment Statuses
bohdan-vorona Mar 3, 2023
702e08f
Customers drop-down only for the current user
bohdan-vorona Mar 3, 2023
db96920
Reconnect uninstalled shop
bohdan-vorona Mar 6, 2023
d16f7b5
Send notification once a shop is uninstalled
bohdan-vorona Mar 6, 2023
acfd526
E-commerce orders logs
bohdan-vorona Mar 6, 2023
62575e6
Added Shopify orders parsing to Cron
bohdan-vorona Mar 7, 2023
604978c
Updated docs
bohdan-vorona Mar 7, 2023
188ac99
Updated docs
bohdan-vorona Mar 7, 2023
f96667f
Removed test action
bohdan-vorona Mar 7, 2023
1561462
Register Shopify webhook listeners logic
bohdan-vorona Mar 9, 2023
29618aa
E-commerce webhooks + MetaDataFieldTrait + updated docs
bohdan-vorona Mar 9, 2023
e964d06
Mandatory webhooks + docs updated
bohdan-vorona Mar 10, 2023
7b95cf2
Cron -> runEcommerceWebhooks(), EcommerceWebhook -> statuses, BaseWeb…
bohdan-vorona Mar 10, 2023
ccc27a0
Dummy webhook status update
bohdan-vorona Mar 13, 2023
da3f580
Unregister Shopify Webhook Listeners Job
bohdan-vorona Mar 13, 2023
26e2d3e
Shopify raw order parsing -> phone number + email
bohdan-vorona Mar 13, 2023
ab813ca
Shopify API -> Fixed issues with its exceptions
bohdan-vorona Mar 13, 2023
382a343
Shop disconnect fix + Find e-commerce integration by meta key
bohdan-vorona Mar 13, 2023
20c1d8b
UnregisterShopifyWebhookListenersJob
bohdan-vorona Mar 13, 2023
639934a
ShopifyShopRedactJob
bohdan-vorona Mar 13, 2023
6373007
ShopifyCustomerRedactJob
bohdan-vorona Mar 13, 2023
682e02a
ShopifyCustomerDataRequestJob
bohdan-vorona Mar 13, 2023
370bb61
ShopifyOrderCancelledJob
bohdan-vorona Mar 13, 2023
38f752e
ShopifyOrderDeletedJob
bohdan-vorona Mar 13, 2023
52babfb
ShopifyOrderUpdatedJob
bohdan-vorona Mar 14, 2023
8c296b9
ShopifyOrderCreatedJob
bohdan-vorona Mar 14, 2023
ba90391
Order Notes
bohdan-vorona Mar 14, 2023
b0b98ff
Updated docs + removed test code
bohdan-vorona Mar 16, 2023
aa84b5c
Shopify OAuth implementation
bohdan-vorona Feb 25, 2023
44db9c9
Some changes in the logic + actions {disconnect/pause/resume}
bohdan-vorona Feb 27, 2023
e938c68
Shopify documentation
bohdan-vorona Feb 27, 2023
0fd3bcc
Connected shops
bohdan-vorona Feb 27, 2023
fc9557f
Update
bohdan-vorona Mar 2, 2023
19f187c
Added: Order Statuses, Financial Statuses, Fulfillment Statuses
bohdan-vorona Mar 3, 2023
709d00c
Customers drop-down only for the current user
bohdan-vorona Mar 3, 2023
2f19d27
Reconnect uninstalled shop
bohdan-vorona Mar 6, 2023
379132b
Send notification once a shop is uninstalled
bohdan-vorona Mar 6, 2023
9e261fb
E-commerce orders logs
bohdan-vorona Mar 6, 2023
27c4c3a
Added Shopify orders parsing to Cron
bohdan-vorona Mar 7, 2023
39f776b
Updated docs
bohdan-vorona Mar 7, 2023
1be29ba
Updated docs
bohdan-vorona Mar 7, 2023
0cd8f3e
Removed test action
bohdan-vorona Mar 7, 2023
0d529d7
Register Shopify webhook listeners logic
bohdan-vorona Mar 9, 2023
0ef08ef
E-commerce webhooks + MetaDataFieldTrait + updated docs
bohdan-vorona Mar 9, 2023
912b868
Mandatory webhooks + docs updated
bohdan-vorona Mar 10, 2023
565ac2a
Cron -> runEcommerceWebhooks(), EcommerceWebhook -> statuses, BaseWeb…
bohdan-vorona Mar 10, 2023
a4670cf
Dummy webhook status update
bohdan-vorona Mar 13, 2023
0e6f47a
Unregister Shopify Webhook Listeners Job
bohdan-vorona Mar 13, 2023
1294781
Shopify raw order parsing -> phone number + email
bohdan-vorona Mar 13, 2023
f09ced3
Shopify API -> Fixed issues with its exceptions
bohdan-vorona Mar 13, 2023
3dc6c74
Shop disconnect fix + Find e-commerce integration by meta key
bohdan-vorona Mar 13, 2023
12b5cd5
UnregisterShopifyWebhookListenersJob
bohdan-vorona Mar 13, 2023
0f7a25a
ShopifyShopRedactJob
bohdan-vorona Mar 13, 2023
492e73c
ShopifyCustomerRedactJob
bohdan-vorona Mar 13, 2023
696cf16
ShopifyCustomerDataRequestJob
bohdan-vorona Mar 13, 2023
dacf575
ShopifyOrderCancelledJob
bohdan-vorona Mar 13, 2023
04c3c80
ShopifyOrderDeletedJob
bohdan-vorona Mar 13, 2023
2ff5e13
ShopifyOrderUpdatedJob
bohdan-vorona Mar 14, 2023
51a70da
ShopifyOrderCreatedJob
bohdan-vorona Mar 14, 2023
51b1503
Order Notes
bohdan-vorona Mar 14, 2023
2f4e4d8
Updated docs + removed test code
bohdan-vorona Mar 16, 2023
79543f7
Merge branch 'feature/shopify-integration' of https://github.com/CGSm…
bohdan-vorona Mar 16, 2023
6bfc6c6
Merge branch 'master' into feature/shopify-integration
bohdan-vorona Mar 16, 2023
7f4e181
Updated migrations - added some indexes
bohdan-vorona Mar 20, 2023
352464a
Changes.
bohdan-vorona Mar 22, 2023
37b3819
Order history -> Added System user
bohdan-vorona Mar 22, 2023
ff05a8c
Orders removed limit parameter.
bohdan-vorona Mar 22, 2023
b88b7bc
m230221_134343_add_shopify_mock_ecommerce_platform
bohdan-vorona Mar 23, 2023
ef92334
Removed runEcommerceIntegrations() from CRON
bohdan-vorona Mar 28, 2023
5cbe6c0
Customer Order #
bohdan-vorona Mar 28, 2023
aca05b7
ShopifyOrderRefundJob mock job
bohdan-vorona Mar 28, 2023
3434937
Updated docs
bohdan-vorona Mar 28, 2023
0ddcacd
Cron Controller update
bohdan-vorona Mar 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ Example of importing a gzipped mysql dump:
1. Install composer and run `composer install` on the root directory
1. Run `php init` for development

Frontend: localhost:30000 API: localhost:30001 MySQL: localhost:30002 PhpMyAdmin: localhost:30003 Shopify: localhost:
30004
Frontend: localhost:30000
API: localhost:30001
MySQL: localhost:30002
PhpMyAdmin: localhost:30003

### Running queue jobs locally

Expand Down
78 changes: 0 additions & 78 deletions api/modules/v1/models/mappers/ShopifyMapper.php

This file was deleted.

1 change: 0 additions & 1 deletion common/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@api', dirname(dirname(__DIR__)) . '/api');
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('@shopify', dirname(dirname(__DIR__)) . '/shopify');
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
22 changes: 16 additions & 6 deletions common/config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
'user.passwordResetTokenExpire' => 3600,
'stripePublicKey' => '1234',
'stripePrivateKey' => '1234',
'shopifyPublicKey' => '5678',
'shopifyPrivateKey' => '5678',
'encryptionKey' => 'secret',
'digitalOceanKey' => 'key',
'digitalOceanSecret' => 'secret',
Expand All @@ -18,10 +16,6 @@
'clientId' => 'lolno',
'secret' => 'lulz',
],
/**
* Shopify App Parameters and App Credentials
*/


/**
* Put here default values for when customers meta value does not exist
Expand Down Expand Up @@ -69,4 +63,20 @@
'csvBoxS3Bucket' => '',
'csvBoxS3Path' => '',
'csvBoxImportKey' => '',

/**
* Shopify
*/
'shopify' => [
/**
* Visit https://partners.shopify.com/ -> Apps -> Your App -> Overview -> Client credentials
*/
'client_id' => '',
'client_secret' => '',
/**
* You can set `https://shipwise.ngrok.io` to test it locally.
* Otherwise, if leave the default value, the current server's domain name will be used automatically.
*/
'override_redirect_domain' => false,
],
];
108 changes: 108 additions & 0 deletions common/models/EcommerceIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace common\models;

use Yii;
use yii\helpers\Html;
use common\models\base\BaseEcommerceIntegration;
use console\jobs\NotificationJob;
use common\traits\MetaDataFieldTrait;
use common\services\platforms\ShopifyService;

/**
* Class EcommerceIntegration
* @package common\models
*/
class EcommerceIntegration extends BaseEcommerceIntegration
{
use MetaDataFieldTrait;

public const STATUS_INTEGRATION_CONNECTED = 1;
public const STATUS_INTEGRATION_PAUSED = 0;
public const STATUS_INTEGRATION_UNINSTALLED = -1;

public function init(): void
{
parent::init();
$this->on(self::EVENT_AFTER_FIND, [$this, 'convertMetaData']);
}

public static function getStatuses(): array
{
return [
self::STATUS_INTEGRATION_CONNECTED => 'Connected',
self::STATUS_INTEGRATION_PAUSED => 'Paused',
self::STATUS_INTEGRATION_UNINSTALLED => 'Uninstalled',
];
}

public function isConnected(): bool
{
return $this->status === self::STATUS_INTEGRATION_CONNECTED;
}

public function isPaused(): bool
{
return $this->status === self::STATUS_INTEGRATION_PAUSED;
}

public function isUninstalled(): bool
{
return $this->status === self::STATUS_INTEGRATION_UNINSTALLED;
}

/**
* @throws \yii\db\StaleObjectException
* @throws \Throwable
* @throws \yii\base\InvalidConfigException
*/
public function disconnect(): bool|int
{
switch ($this->ecommercePlatform->name) {
case EcommercePlatform::SHOPIFY_PLATFORM_NAME:

$shopifyService = new ShopifyService($this->array_meta_data['shop_url'], $this);
$shopifyService->deleteWebhookListenersJob();

break;
}

return $this->delete();
}

public function uninstall(bool $withNotification = false): void
{
$this->status = self::STATUS_INTEGRATION_UNINSTALLED;
$this->save();

if ($withNotification) {
$shopUrl = Html::encode($this->array_meta_data['shop_url']);
$subject = '⚠️ Problem pulling data from ' . $shopUrl;
$message = 'We were not able to pull data from the Shopify shop ' . $shopUrl .'.';
$message .= ' The status of the shop is changed to `Uninstalled`.';
$message .= ' Please click the link below and try to reconnect the shop.';

Yii::$app->queue->push(
new NotificationJob([
'customer_id' => $this->customer_id,
'subject' => $subject,
'message' => $message,
'url' => ['/ecommerce-integration/index'],
'urlText' => 'Reconnect the shop',
])
);
}
}

public function pause(): bool
{
$this->status = self::STATUS_INTEGRATION_PAUSED;
return $this->save();
}

public function resume(): bool
{
$this->status = self::STATUS_INTEGRATION_CONNECTED;
return $this->save();
}
}
51 changes: 51 additions & 0 deletions common/models/EcommerceOrderLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace common\models;

use yii\helpers\Json;
use common\models\base\BaseEcommerceOrderLog;
use common\traits\MetaDataFieldTrait;

/**
* Class EcommerceOrderLog
* @package common\models
*/
class EcommerceOrderLog extends BaseEcommerceOrderLog
{
use MetaDataFieldTrait;

public const STATUS_SUCCESS = 'success';
public const STATUS_FAILED = 'failed';

public static function getStatuses(): array
{
return [
self::STATUS_SUCCESS => 'Success',
self::STATUS_FAILED => 'Failed',
];
}

public static function success(EcommerceIntegration $ecommerceIntegration, array $payload, Order $order): void
{
$ecommerceOrderLog = new EcommerceOrderLog();
$ecommerceOrderLog->platform_id = $ecommerceIntegration->ecommercePlatform->id;
$ecommerceOrderLog->integration_id = $ecommerceIntegration->id;
$ecommerceOrderLog->original_order_id = (string)$payload['id'];
$ecommerceOrderLog->internal_order_id = $order->id;
$ecommerceOrderLog->status = self::STATUS_SUCCESS;
$ecommerceOrderLog->payload = Json::encode($payload, JSON_PRETTY_PRINT);
$ecommerceOrderLog->save();
}

public static function failed(EcommerceIntegration $ecommerceIntegration, array $payload, ?array $meta = null): void
{
$ecommerceOrderLog = new EcommerceOrderLog();
$ecommerceOrderLog->platform_id = $ecommerceIntegration->ecommercePlatform->id;
$ecommerceOrderLog->integration_id = $ecommerceIntegration->id;
$ecommerceOrderLog->original_order_id = (string)$payload['id'];
$ecommerceOrderLog->status = self::STATUS_FAILED;
$ecommerceOrderLog->payload = Json::encode($payload, JSON_PRETTY_PRINT);
$ecommerceOrderLog->meta = ($meta) ? Json::encode($meta, JSON_PRETTY_PRINT) : null;
$ecommerceOrderLog->save();
}
}
57 changes: 57 additions & 0 deletions common/models/EcommercePlatform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace common\models;

use yii\db\ActiveQuery;
use common\models\base\BaseEcommercePlatform;
use common\traits\MetaDataFieldTrait;

/**
* Class EcommercePlatform
* @package common\models
*/
class EcommercePlatform extends BaseEcommercePlatform
{
use MetaDataFieldTrait;

public const STATUS_PLATFORM_ACTIVE = 1;
public const STATUS_PLATFORM_INACTIVE = 0;

public const SHOPIFY_PLATFORM_NAME = 'Shopify';

public static function getStatuses(): array
{
return [
self::STATUS_PLATFORM_ACTIVE => 'Active',
self::STATUS_PLATFORM_INACTIVE => 'Inactive',
];
}

public function getEcommerceIntegration(): ActiveQuery
{
return $this->hasOne(EcommerceIntegration::class, ['platform_id' => 'id']);
}

public function isActive(): bool
{
return $this->status === self::STATUS_PLATFORM_ACTIVE;
}

public function switchStatus(): void
{
$this->status = ($this->isActive()) ? self::STATUS_PLATFORM_INACTIVE : self::STATUS_PLATFORM_ACTIVE;
$this->save();
}

public function getConnectedShopsCounter(): int
{
return EcommerceIntegration::find()
->where(['platform_id' => $this->id])
->count();
}

public static function getShopifyObject(): ?EcommercePlatform
{
return self::findOne(['name' => self::SHOPIFY_PLATFORM_NAME]);
}
}
Loading