| <?php |
| <?php |
| |
| |
| namespace App\Jobs; |
| namespace App\Jobs; |
| |
| |
| require_once(dirname(__FILE__).'/../../vendor/autoload.php'); |
| require_once(dirname(__FILE__).'/../../vendor/autoload.php'); |
| |
| |
| use Illuminate\Bus\Queueable; |
| use Illuminate\Bus\Queueable; |
| use Illuminate\Queue\SerializesModels; |
| use Illuminate\Queue\SerializesModels; |
| use Illuminate\Queue\InteractsWithQueue; |
| use Illuminate\Queue\InteractsWithQueue; |
| use Illuminate\Contracts\Queue\ShouldQueue; |
| use Illuminate\Contracts\Queue\ShouldQueue; |
| use Illuminate\Foundation\Bus\Dispatchable; |
| use Illuminate\Foundation\Bus\Dispatchable; |
| use Illuminate\Support\Facades\File; |
| use Illuminate\Support\Facades\File; |
| use Config; |
| use Config; |
| use Log; |
| use Log; |
| |
| |
| use OhMyBrew\BasicShopifyAPI; |
| use OhMyBrew\BasicShopifyAPI; |
| |
| |
| |
| |
| class CreateShopifyCustomerJob implements ShouldQueue |
| class CreateShopifyCustomerJob implements ShouldQueue |
| { |
| { |
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
| |
| |
| public $email; |
| public $email; |
| public $userName; |
| public $userName; |
| public $partnerValue; |
| public $partnerValue; |
| public $shopify_api_version; |
| public $shopify_api_version; |
| |
| |
| /** |
| /** |
| * Create a new job instance. |
| * Create a new job instance. |
| * |
| * |
| * @return void |
| * @return void |
| */ |
| */ |
| public function __construct($customerDetails) |
| public function __construct($customerDetails) |
| { |
| { |
| $this->email = $customerDetails['email']; |
| $this->email = $customerDetails['email']; |
| $this->userName = $customerDetails['userName']; |
| $this->userName = $customerDetails['userName']; |
| $this->partnerValue = (isset($customerDetails['partnerValue']))?$customerDetails['partnerValue']:''; |
| $this->partnerValue = (isset($customerDetails['partnerValue']))?$customerDetails['partnerValue']:''; |
| $this->shopify_api_version = env('SHOPIFY_API_VERSION', true); |
| $this->shopify_api_version = env('SHOPIFY_API_VERSION', true); |
| } |
| } |
| |
| |
| /** |
| /** |
| * Execute the job. |
| * Execute the job. |
| * @return void |
| * @return void |
| */ |
| */ |
| public function handle() |
| public function handle() |
| { |
| { |
| |
| |
| $api = new BasicShopifyAPI(); |
| $api = new BasicShopifyAPI(); |
| |
| |
. | $password = Config::get('shopify.password'); |
| $password = Config::get('shopify.passwordQuiz'); |
| $shopDomain = Config::get('shopify.shopDomain'); |
| $shopDomain = Config::get('shopify.shopDomainQuiz'); |
| |
| |
| $api->setShop($shopDomain); |
| $api->setShop($shopDomain); |
| $api->setAccessToken($password); |
| $api->setAccessToken($password); |
| |
| |
| $tags = []; |
| $tags = []; |
| if(trim($this->partnerValue) != ''){ |
| if(trim($this->partnerValue) != ''){ |
| $tags[] = "partner:".$this->partnerValue; |
| $tags[] = "partner:".$this->partnerValue; |
| } |
| } |
| |
| |
| $params = array( |
| $params = array( |
| 'customer' => array( |
| 'customer' => array( |
| 'email' => $this->email, |
| 'email' => $this->email, |
| 'first_name' => $this->userName, |
| 'first_name' => $this->userName, |
. | 'tags' => $tags |
| 'tags' => $tags |
| ) |
| ) |
| ); |
| ); |
. | |
| //sleep(1); |
| |
| Log::info($this->partnerValue); |
| |
| |
. | // Log::info(print_r($params)); |
| Log::info(json_encode($params)); |
| |
| $retry = false; |
| $result = $api->rest('POST', '/admin/api/'.$this->shopify_api_version.'/customers.json', $params); |
| $try = 1; |
| |
| do{ |
| |
| Log::info($try.' try-create shopify customer '); |
| |
| $result = $api->rest('POST', '/admin/api/'.$this->shopify_api_version.'/customers.json', $params); |
| |
| if(!isset($result->body->customer->id)){ |
| |
| $retry = true; |
| |
| $try++; |
| |
| } |
| |
| } while($retry && $try <=3); |
| |
| Log::info(json_encode($result)); |
| |
| |
| if(empty($result->errors)) //success |
| if(empty($result->errors)) //success |
| { |
| { |
| // TO DO |
| // TO DO |
| } |
| } |
| else //error |
| else //error |
| { |
| { |
| // TO DO |
| // TO DO |
| } |
| } |
| |
| |
| } |
| } |
| } |
| } |
| |
| |