Skip to content

Commit

Permalink
Merge pull request #1 from alldigitalrewards/DS-5017-v3
Browse files Browse the repository at this point in the history
DS-5017 CreateOrderCode using this to generate a URL for the participant
  • Loading branch information
jmuto2 authored Apr 3, 2023
2 parents 8f16cab + 6c9983c commit 899f7d1
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 159 deletions.
2 changes: 1 addition & 1 deletion examples/accessTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
$client = new Client();
/** @var AccessTokenResponse $accessTokenResponse */
$accessTokenResponse = $client->request($request);
var_dump($accessTokenResponse->getAccessToken());
var_dump($accessTokenResponse->getAccessToken());
21 changes: 21 additions & 0 deletions examples/createOrderCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use AllDigitalRewards\NeoCurrency\Client;
use AllDigitalRewards\NeoCurrency\Order\OrderCodeRequest;
use AllDigitalRewards\NeoCurrency\Order\OrderCodeResponse;

require __DIR__ . '/../vendor/autoload.php';

$request = new OrderCodeRequest(
'aclientid',
'someaccesstoken',
1, // use the USD campaign, whatever yours is note prod and sandbox will be different
100, // this is the Product (Brand) id you want to purchase
"1.00",
);

$client = new Client();
/** @var OrderCodeResponse $order */
$order = $client->request($request);
print_r($order->getOrder()->getOrderId());
print_r($order->getCodeUrl());
23 changes: 0 additions & 23 deletions examples/createOrderNow.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Auth/AccessTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
) {
parent::__construct(
"POST",
$this->getAccessTokenUrl(),
$this->getBaseUrl() . '/api/get-token',
['Content-Type' => 'application/json'],
$this->makeJsonBody($clientId, $clientSecret, $email, $password)
);
Expand Down
78 changes: 56 additions & 22 deletions src/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,82 @@
namespace AllDigitalRewards\NeoCurrency\Order;

use AllDigitalRewards\NeoCurrency\AbstractEntity;
use Exception;

class Order extends AbstractEntity
{
protected $campaign_brand_id;
protected $denomination;
protected $currency;
protected $codes;
protected $uuids;
protected $order_id;
protected $custom1;
protected $data;

public function getOrderId()
public function getCampaignBrandId()
{
return $this->order_id;
return $this->campaign_brand_id;
}

public function setOrderId($order_id): void
public function setCampaignBrandId($campaign_brand_id): void
{
$this->order_id = $order_id;
$this->campaign_brand_id = $campaign_brand_id;
}

public function getCustom1()
public function getDenomination()
{
return $this->custom1;
return $this->denomination;
}

public function setCustom1($custom1): void
public function setDenomination($denomination): void
{
$this->custom1 = $custom1;
$this->denomination = $denomination;
}

public function getData()
public function getCurrency()
{
return $this->data;
return $this->currency;
}

public function setCurrency($currency): void
{
$this->currency = $currency;
}

public function getCodes()
{
return $this->codes;
}

public function setCodes($codes): void
{
$this->codes = $codes;
}

public function getUuids()
{
return $this->uuids;
}

public function setUuids($uuids): void
{
$this->uuids = $uuids;
}

public function getOrderId()
{
return $this->order_id;
}

public function setOrderId($order_id): void
{
$this->order_id = $order_id;
}

public function setData($data): void
/**
* @throws Exception
*/
public function getOrderCode()
{
if (!empty($data) && is_array($data)) {
$infoCollection = [];
foreach ($data as $info) {
$infoCollection[] = new OrderInfo($info);
}
$this->data = $infoCollection;
return;
}
$this->data = $data;
return $this->getCodes()[0] ?? throw new Exception('Code not present');
}
}
25 changes: 9 additions & 16 deletions src/Order/OrderNowRequest.php → src/Order/OrderCodeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,54 @@
use AllDigitalRewards\NeoCurrency\AbstractRequest;
use AllDigitalRewards\NeoCurrency\HasResponse;

class OrderNowRequest extends AbstractRequest implements HasResponse
class OrderCodeRequest extends AbstractRequest implements HasResponse
{
private int $brandId;
private float $denomination;
private int $quantity;
private string $poNumber;
private string $email;
private int $campaignId;
private string $clientId;

public function __construct(
string $clientId,
string $accessToken,
int $campaignId,
int $brandId,
string $denomination,
int $quantity = 1,
string $poNumber = '',
string $email = ''
) {
$this->clientId = $clientId;
$this->accessToken = $accessToken;
$this->campaignId = $campaignId;
$this->brandId = $brandId;
$this->denomination = $denomination;
$this->quantity = $quantity;
$this->poNumber = $poNumber;
$this->email = $email;
$this->setUpRequest();
}

private function setUpRequest()
{
parent::__construct(
"POST",
$this->getBaseUrl() . '/createordernow',
$this->getBaseUrl() . '/codes/create',
$this->getRequestHeaders(),
$this->makeJsonBody()
);
}

public function getResponseObject(): string
{
return OrderResponse::class;
return OrderCodeResponse::class;
}

private function makeJsonBody(): string
{
return json_encode(
[
'client_id' => $this->clientId,
'purchase_order_number' => $this->poNumber,
'custom1' => $this->email,
'campaign_id' => $this->campaignId,
'brands' => [
[
"id" => $this->brandId,
"denomination" => $this->denomination,
"quantity" => $this->quantity,
"quantity" => 1,
"client_id" => $this->clientId,
]
]
],
Expand Down
22 changes: 16 additions & 6 deletions src/Order/OrderResponse.php → src/Order/OrderCodeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
namespace AllDigitalRewards\NeoCurrency\Order;

use AllDigitalRewards\NeoCurrency\AbstractResponse;
use AllDigitalRewards\NeoCurrency\Traits\HasEnvironmentsTrait;
use Exception;

class OrderResponse extends AbstractResponse
class OrderCodeResponse extends AbstractResponse
{
private $order = null;
use HasEnvironmentsTrait;

private Order $order;

/**
* @throws Exception
*/
public function extractData(array $data): AbstractResponse
{
if (empty($data['success'])) {
if (empty($data['success'][0])) {
throw new Exception('Order Failure');
}

$order = new Order($data['success']);
$order = new Order($data['success'][0]);
$this->setOrder($order);
return $this;
}
Expand All @@ -28,8 +30,16 @@ private function setOrder(Order $order)
$this->order = new Order($order);
}

public function getOrder(): ?Order
public function getOrder(): Order
{
return $this->order;
}

/**
* @throws Exception
*/
public function getCodeUrl(): string
{
return $this->getActivateCodeBaseUrl() . '/' . $this->getOrder()->getOrderCode();
}
}
64 changes: 0 additions & 64 deletions src/Order/OrderInfo.php

This file was deleted.

Loading

0 comments on commit 899f7d1

Please sign in to comment.