Skip to content

Commit

Permalink
Basic usage and code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
marrek13 committed Feb 1, 2018
1 parent bb94fc0 commit a3c10a6
Show file tree
Hide file tree
Showing 25 changed files with 245 additions and 222 deletions.
119 changes: 103 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,106 @@ PHP SDK for Bonanza Marketplace and its "Bonapitit" REST API.

Package currently has got support for calling Bonanza's methods:

* fetchToken
* getBoothItems
* getCategories
* getCategoryTraits
* getOrders
* getSingleItem
* getUnlistedItem
* getUser
* addFixedPriceItem
* reviseFixedPriceItem
* endFixedPriceItem
* updateBooth
* setNotificationPreferences
* getNotificationPreferences

Please refer to the Bonanza's API docs here: https://api.bonanza.com/docs
| Method name | Is secure |
| ------------- | ------------- |
| fetchToken | no |
| getCategories | no |
| getCategoryTraits | no |
| getSingleItem | no |
| getBoothItems | for basic data - no, for more detailed data - yes|
| getUnlistedItem | yes |
| getOrders | yes |
| getUser | yes |
| addFixedPriceItem | yes |
| reviseFixedPriceItem | yes |
| endFixedPriceItem | yes |
| updateBooth | yes |
| setNotificationPreferences | yes |
| getNotificationPreferences | yes |

Please refer to the Bonanza's API docs here: https://api.bonanza.com/docs

# Basic usage

For every call you need devID and certID that you can obtain here: https://api.bonanza.com/accounts/new

###Unsecure calls

```php
<?php

use Shoplo\BonanzaApi\Client\BonanzaClient;
use Shoplo\BonanzaApi\Credentials\Credentials;
use Shoplo\BonanzaApi\Request\GetBoothItemsRequest;

//Create credentials object using obtained data
$credentials = new Credentials('devID', 'certID');

//Create bonanza client
$client = new BonanzaClient($credentials);

//Create request
$request = new GetBoothItemsRequest();
$request->page = 1;
$request->itemsPerPage = 3;
$request->boothId = 'boothName';

//Make a call and receive GetBoothItemsResponse object
$response = $client->getBoothItems($request);
```

###Secure calls

To make secure call, you need to obtain user auth token first.
To receive it, you need to make fetchToken call:

```php
<?php

use Shoplo\BonanzaApi\Request\FetchTokenRequest;

//Create request, and provide the callback url
$request = new FetchTokenRequest();
$request->validationCompleteURL = 'http://return.to/url';

//Make a call and get the authorization URL
$response = $client->fetchToken($request);

//You have the auth token here, but it is inactive, so you can save it for example in the session
$authToken = $response->fetchTokenResponse->authToken;

//Then you redirect user to the page, where he need to log in and confirm the token.
// After confirmation the user is taken back to the validationCompleteURL.
header('Location: '.$response->fetchTokenResponse->authenticationURL);
```

When the access token is signed, you can make a secure call.

```php
<?php

use Shoplo\BonanzaApi\Client\BonanzaClient;
use Shoplo\BonanzaApi\Credentials\Credentials;
use Shoplo\BonanzaApi\Request\GetBoothItemsRequest;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

//Create credentials object using obtained data
$credentials = new Credentials('devID', 'certID');

//Create bonanza client
$client = new BonanzaClient($credentials);

//Create requester credentials containing the received token
$requesterCredentials = new RequesterCredentialsType();
$requesterCredentials->bonanzleAuthToken = 'authToken';

//Create request and pass the requesterCredentials to authorize the request
$request = new GetBoothItemsRequest();
$request->requesterCredentials = $requesterCredentials;
$request->page = 1;
$request->itemsPerPage = 3;
$request->boothId = 'boothName';

//Make a call and receive GetBoothItemsResponse object
$response = $client->getBoothItems($request);
```
18 changes: 9 additions & 9 deletions src/Shoplo/BonanzaApi/Client/BonanzaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ public function updateBooth(UpdateBoothRequest $request): UpdateBoothResponse
return $this->post(__FUNCTION__, $request, true);
}

public function setNotificationPreferences(SetNotificationPreferencesRequest $request): SetNotificationPreferencesResponse
{
return $this->post(__FUNCTION__, $request, true);
}

public function getNotificationPreferences(GetNotificationPreferencesRequest $request): GetNotificationPreferencesResponse
{
return $this->post(__FUNCTION__, $request, true);
}
public function setNotificationPreferences(SetNotificationPreferencesRequest $request): SetNotificationPreferencesResponse
{
return $this->post(__FUNCTION__, $request, true);
}

public function getNotificationPreferences(GetNotificationPreferencesRequest $request): GetNotificationPreferencesResponse
{
return $this->post(__FUNCTION__, $request, true);
}
}
1 change: 0 additions & 1 deletion src/Shoplo/BonanzaApi/Credentials/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Credentials implements CredentialsInterface
private $devId;

/**
* @param string $appId Application ID
* @param string $certId Certificate ID
* @param string $devId Developer ID
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Shoplo/BonanzaApi/Enums/DeliveryUrlDetailsStatusType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class DeliveryUrlDetailsStatusType
{
const STATUS_ENABLE = 'Enable';
const STATUS_DISABLE = 'Disable';
const STATUS_ENABLE = 'Enable';
const STATUS_DISABLE = 'Disable';
}
4 changes: 2 additions & 2 deletions src/Shoplo/BonanzaApi/Enums/NotificationEnableStatusType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class NotificationEnableStatusType
{
const ENABLE = 'Enable';
const DISABLE = 'Disable';
const ENABLE = 'Enable';
const DISABLE = 'Disable';
}
8 changes: 4 additions & 4 deletions src/Shoplo/BonanzaApi/Enums/NotificationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class NotificationType
{
const ASK_SELLER_QUESTION = 'askSellerQuestion';
const FEEDBACK = 'feedback';
const FIXED_PRICE_TRANSACTION = 'fixedPriceTransaction';
const ITEM_MARKED_SHIPPED = 'itemMarkedShipped';
const ASK_SELLER_QUESTION = 'askSellerQuestion';
const FEEDBACK = 'feedback';
const FIXED_PRICE_TRANSACTION = 'fixedPriceTransaction';
const ITEM_MARKED_SHIPPED = 'itemMarkedShipped';
}
16 changes: 8 additions & 8 deletions src/Shoplo/BonanzaApi/Enums/PackageSizeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class PackageSizeType
{
const DIGITAL_DOWNLOAD = 'Digital download';
const LARGE_ENVELOPE = 'Large envelope';
const NORMAL_PACKAGE = 'Normal package';
const LARGE_PACKAGE = 'Large package';
const VERY_LARGE_PACKAGE = 'Very large package';
const USPS_PRIORITY_MAIL_SMALL_FLAT_RATE_BOX = 'USPS Priority Mail Small Flat Rate Box';
const USPS_PRIORITY_MAIL_MEDIUM_FLAT_RATE_BOX = 'USPS Priority Mail Medium Flat Rate Box';
const USPS_PRIORITY_MAIL_LARGE_FLAT_RATE_BOX = 'USPS Priority Mail Large Flat Rate Box';
const DIGITAL_DOWNLOAD = 'Digital download';
const LARGE_ENVELOPE = 'Large envelope';
const NORMAL_PACKAGE = 'Normal package';
const LARGE_PACKAGE = 'Large package';
const VERY_LARGE_PACKAGE = 'Very large package';
const USPS_PRIORITY_MAIL_SMALL_FLAT_RATE_BOX = 'USPS Priority Mail Small Flat Rate Box';
const USPS_PRIORITY_MAIL_MEDIUM_FLAT_RATE_BOX = 'USPS Priority Mail Medium Flat Rate Box';
const USPS_PRIORITY_MAIL_LARGE_FLAT_RATE_BOX = 'USPS Priority Mail Large Flat Rate Box';
const USPS_PRIORITY_MAIL_FLAT_RATE_ENVELOPE = 'USPS Priority Mail Flat Rate Envelope';
const USPS_PRIORITY_MAIL_PADDED_FLAT_RATE_ENVELOPE = 'USPS Priority Mail Padded Flat Rate Envelope';
const USPS_PRIORITY_MAIL_LEGAL_FLAT_RATE_ENVELOPE = 'USPS Priority Mail Legal Flat Rate Envelope';
Expand Down
9 changes: 1 addition & 8 deletions src/Shoplo/BonanzaApi/Request/AddFixedPriceItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@
use Shoplo\BonanzaApi\Type\AddItemType;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

class AddFixedPriceItemRequest
class AddFixedPriceItemRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;

/**
* @var AddItemType
*
Expand Down
9 changes: 1 addition & 8 deletions src/Shoplo/BonanzaApi/Request/EndFixedPriceItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@
use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

class EndFixedPriceItemRequest
class EndFixedPriceItemRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;

/**
* @var int
*
Expand Down
9 changes: 1 addition & 8 deletions src/Shoplo/BonanzaApi/Request/GetBoothItemsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@
use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

class GetBoothItemsRequest
class GetBoothItemsRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;

/**
* @var string
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@

namespace Shoplo\BonanzaApi\Request;

use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\AddItemType;
use Shoplo\BonanzaApi\Type\DeliveryURLDetailsType;
use Shoplo\BonanzaApi\Type\ApplicationDeliveryPreferencesType;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;
use Shoplo\BonanzaApi\Type\UserDeliveryPreferenceArrayType;

class GetNotificationPreferencesRequest
class GetNotificationPreferencesRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;
}
9 changes: 1 addition & 8 deletions src/Shoplo/BonanzaApi/Request/GetOrdersRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@
use Shoplo\BonanzaApi\Type\PaginationInputType;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

class GetOrdersRequest
class GetOrdersRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;

/**
* @var \DateTime
*
Expand Down
10 changes: 1 addition & 9 deletions src/Shoplo/BonanzaApi/Request/GetUnlistedItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@


use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

class GetUnlistedItemRequest
class GetUnlistedItemRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;

/**
* @var string
*
Expand Down
11 changes: 1 addition & 10 deletions src/Shoplo/BonanzaApi/Request/GetUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
namespace Shoplo\BonanzaApi\Request;


use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

class GetUserRequest
class GetUserRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;
}
18 changes: 18 additions & 0 deletions src/Shoplo/BonanzaApi/Request/SecureRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php


namespace Shoplo\BonanzaApi\Request;


use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;

abstract class SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@
namespace Shoplo\BonanzaApi\Request;

use JMS\Serializer\Annotation as Serializer;
use Shoplo\BonanzaApi\Type\AddItemType;
use Shoplo\BonanzaApi\Type\DeliveryURLDetailsType;
use Shoplo\BonanzaApi\Type\ApplicationDeliveryPreferencesType;
use Shoplo\BonanzaApi\Type\RequesterCredentialsType;
use Shoplo\BonanzaApi\Type\UserDeliveryPreferenceArrayType;

class SetNotificationPreferencesRequest
class SetNotificationPreferencesRequest extends SecureRequest
{
/**
* @var RequesterCredentialsType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\RequesterCredentialsType")
*/
public $requesterCredentials;

/**
* @var ApplicationDeliveryPreferencesType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\ApplicationDeliveryPreferencesType")
*/
public $applicationDeliveryPreferences;

/**
* @var UserDeliveryPreferenceArrayType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\UserDeliveryPreferenceArrayType")
*/
public $userDeliveryPreferenceArray;
/**
* @var UserDeliveryPreferenceArrayType
*
* @Serializer\Type("Shoplo\BonanzaApi\Type\UserDeliveryPreferenceArrayType")
*/
public $userDeliveryPreferenceArray;
}
Loading

0 comments on commit a3c10a6

Please sign in to comment.