Skip to content

Commit 5d34185

Browse files
Updated call URL as wish destroyed v2 auth URL
1 parent 047c732 commit 5d34185

File tree

2 files changed

+84
-69
lines changed

2 files changed

+84
-69
lines changed

src/Wish/WishAuth.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct($client_id,$client_secret,$session_type='prod'){
3838
}
3939

4040
public function getToken($code, $redirect_uri){
41-
$type = 'POST';
41+
$type = 'GET';
4242
$path = 'oauth/access_token';
4343
$params = array(
4444
'client_id'=>$this->client_id,
@@ -64,7 +64,7 @@ public function getToken($code, $redirect_uri){
6464
}
6565

6666
public function refreshToken($refresh_token){
67-
$type = 'POST';
67+
$type = 'GET';
6868
$path = 'oauth/refresh_token';
6969
$params = array(
7070
'client_id'=>$this->client_id,

src/Wish/WishRequest.php

+82-67
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?php
1+
<?php
22
/**
33
* Copyright 2014 Wish.com, ContextLogic or its affiliates. All Rights Reserved.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License").
66
* You may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
8-
*
7+
* You may obtain a copy of the License at
8+
*
99
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
1111
* Unless required by applicable law or agreed to in writing, software
@@ -14,85 +14,100 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
namespace Wish;
1819

1920
use Wish\Exception\ConnectionException;
2021

21-
class WishRequest{
22-
const VERSION = "v2/";
23-
const BASE_PROD_PATH = "https://merchant.wish.com/api/";
24-
const BASE_SANDBOX_PATH = "https://sandbox.merchant.wish.com/api/";
25-
const BASE_STAGE_PATH = "https://merch.corp.contextlogic.com/api/";
26-
private $session;
27-
private $method;
28-
private $path;
29-
private $params;
22+
class WishRequest
23+
{
24+
const VERSION = "v2/";
25+
const BASE_PROD_PATH = "https://merchant.wish.com/api/";
26+
const BASE_SANDBOX_PATH = "https://sandbox.merchant.wish.com/api/";
27+
const BASE_STAGE_PATH = "https://merch.corp.contextlogic.com/api/";
28+
private $session;
29+
private $method;
30+
private $path;
31+
private $params;
3032

31-
public function __construct($session,$method,$path,$params = array()) {
32-
$this->session = $session;
33-
$this->method = $method;
34-
$this->path = $path;
35-
$params['access_token'] = $session->getAccessToken();
36-
if($session->getMerchantId())$params['merchant_id']=$session->getMerchantId();
37-
$this->params = $params;
38-
}
33+
public function __construct($session, $method, $path, $params = array())
34+
{
35+
$this->session = $session;
36+
$this->method = $method;
37+
$this->path = $path;
38+
$params['access_token'] = $session->getAccessToken();
39+
if ($session->getMerchantId()) $params['merchant_id'] = $session->getMerchantId();
40+
$this->params = $params;
41+
}
3942

40-
public function getVersion(){
41-
return static::VERSION;
42-
}
43+
public function getVersion()
44+
{
45+
return static::VERSION;
46+
}
4347

44-
public function getRequestURL(){
45-
switch($this->session->getSessionType()){
46-
case WishSession::SESSION_PROD: return static::BASE_PROD_PATH;
47-
case WishSession::SESSION_SANDBOX: return static::BASE_SANDBOX_PATH;
48-
case WishSession::SESSION_STAGE: return static::BASE_STAGE_PATH;
49-
default: throw new InvalidArgumentException("Invalid session type");
48+
public function getRequestURL()
49+
{
50+
switch ($this->session->getSessionType()) {
51+
case WishSession::SESSION_PROD:
52+
return static::BASE_PROD_PATH;
53+
case WishSession::SESSION_SANDBOX:
54+
return static::BASE_SANDBOX_PATH;
55+
case WishSession::SESSION_STAGE:
56+
return static::BASE_STAGE_PATH;
57+
default:
58+
throw new InvalidArgumentException("Invalid session type");
59+
}
5060
}
51-
}
5261

53-
public function execute(){
54-
$url = $this->getRequestURL().$this->getVersion().$this->path;
55-
$curl = curl_init();
56-
$params = $this->params;
62+
public function execute()
63+
{
64+
$url = $this->getRequestURL();
5765

58-
$options = array(
59-
CURLOPT_CONNECTTIMEOUT => 10,
60-
CURLOPT_RETURNTRANSFER => true,
61-
CURLOPT_ENCODING => '',
62-
CURLOPT_USERAGENT => 'wish-php-sdk',
63-
CURLOPT_HEADER => 'true'
64-
);
66+
// Use v3 for auth, v2 for all other calls, because Wish is INCREDIBLY asinie
67+
if ($this->path == 'oauth/access_token' || $this->path == 'oauth/refresh_token') {
68+
$url .= 'v3/';
69+
} else {
70+
$url .= 'v2/';
71+
}
6572

66-
if($this->method === "GET"){
67-
$url = $url."?".http_build_query($params);
68-
}else {
69-
$options[CURLOPT_POSTFIELDS] = $params;
70-
}
71-
$options[CURLOPT_URL] = $url;
72-
curl_setopt_array($curl, $options);
73+
$url .= $this->path;
74+
$curl = curl_init();
75+
$params = $this->params;
7376

74-
$result = curl_exec($curl);
75-
$error = curl_errno($curl);
76-
77-
$error_message = curl_error($curl);
77+
$options = array(
78+
CURLOPT_CONNECTTIMEOUT => 10,
79+
CURLOPT_RETURNTRANSFER => true,
80+
CURLOPT_ENCODING => '',
81+
CURLOPT_USERAGENT => 'wish-php-sdk',
82+
CURLOPT_HEADER => 'true'
83+
);
7884

79-
if($error){
80-
throw new ConnectionException($error_message);
81-
}
82-
$httpStatus = curl_getinfo($curl,CURLINFO_HTTP_CODE);
83-
$headerSize = curl_getinfo($curl,CURLINFO_HEADER_SIZE);
84-
curl_close($curl);
85-
86-
$decoded_result = json_decode($result);
87-
if($decoded_result === null){
88-
$out = array();
89-
parse_str($result,$out);
90-
return new WishResponse($this,$out,$result);
91-
}
92-
return new WishResponse($this,$decoded_result,$result);
93-
}
85+
if ($this->method === "GET") {
86+
$url = $url . "?" . http_build_query($params);
87+
} else {
88+
$options[CURLOPT_POSTFIELDS] = $params;
89+
}
90+
$options[CURLOPT_URL] = $url;
91+
curl_setopt_array($curl, $options);
9492

93+
$result = curl_exec($curl);
94+
$error = curl_errno($curl);
9595

96+
$error_message = curl_error($curl);
9697

98+
if ($error) {
99+
throw new ConnectionException($error_message);
100+
}
101+
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
102+
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
103+
curl_close($curl);
97104

105+
$decoded_result = json_decode($result);
106+
if ($decoded_result === null) {
107+
$out = array();
108+
parse_str($result, $out);
109+
return new WishResponse($this, $out, $result);
110+
}
111+
return new WishResponse($this, $decoded_result, $result);
112+
}
98113
}

0 commit comments

Comments
 (0)