-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from michaelpo-rm/main
- Loading branch information
Showing
7 changed files
with
417 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace RevenueMonster\SDK\Modules; | ||
|
||
use RevenueMonster\SDK\Request\TokenizedCustomer; | ||
use RevenueMonster\SDK\Request\RecurringCustomer; | ||
use RevenueMonster\SDK\Request\CustomerOrderAmount; | ||
|
||
class TokenizedCustomerModule extends Module | ||
{ | ||
|
||
/** | ||
* Create Recurring Customer | ||
* @param RecurringCustomer $args | ||
* @return stdClass | ||
* @throws ApiException | ||
*/ | ||
public function createRecurringCustomer($args) | ||
{ | ||
if ($args instanceof RecurringCustomer) { | ||
$args = $args->jsonSerialize(); | ||
} | ||
// print_r($args); | ||
|
||
$uri = $this->getOpenApiUrl('v3', '/recurring-payment'); | ||
return $this->mapResponse($this->callApi('post', $uri, $args)->send()); | ||
} | ||
|
||
/** | ||
* Create Tokenized Customer | ||
* @param TokenizedCustomer $args | ||
* @return stdClass | ||
* @throws ApiException | ||
*/ | ||
public function createTokenizedPayment($args) | ||
{ | ||
if ($args instanceof TokenizedCustomer) { | ||
$args = $args->jsonSerialize(); | ||
} | ||
// print_r($args); | ||
|
||
$uri = $this->getOpenApiUrl('v3', '/tokenized-payment'); | ||
return $this->mapResponse($this->callApi('post', $uri, $args)->send()); | ||
} | ||
|
||
|
||
/** | ||
* Toggle customer status by Customer ID | ||
* @param string $customerId | ||
* @return stdClass | ||
* @throws ApiException | ||
*/ | ||
public function toggleCustomerStatusById(string $customerId) | ||
{ | ||
$uri = $this->getOpenApiUrl('v3', "/customer/$customerId/status"); | ||
return $this->mapResponse($this->callApi('put', $uri)->send()); | ||
} | ||
|
||
/** | ||
* Get Customer Orders by Customer ID | ||
* @param string $customerId | ||
* @return stdClass | ||
* @throws ApiException | ||
*/ | ||
public function getCustomerOrdersById(string $customerId) | ||
{ | ||
$uri = $this->getOpenApiUrl('v3', "/customer/$customerId/orders"); | ||
return $this->mapResponse($this->callApi('get', $uri)->send()); | ||
} | ||
|
||
|
||
/** | ||
* Create Customer Order by Customer ID | ||
* @param string $customerId, obj $args | ||
* @return stdClass | ||
* @throws ApiException | ||
*/ | ||
public function createCustomerOrderById(string $customerId, $args) | ||
{ | ||
if ($args instanceof CustomerOrderAmount) { | ||
$args = $args->jsonSerialize(); | ||
} | ||
// print_r($args); | ||
|
||
$uri = $this->getOpenApiUrl('v3', "/customer/$customerId/order"); | ||
return $this->mapResponse($this->callApi('post', $uri, $args)->send()); | ||
} | ||
|
||
/** | ||
* Get Customer Tokens ( Customer ID based on your side pass in to Web Payment ) | ||
* @param string $customerId | ||
* @return stdClass | ||
* @throws ApiException | ||
*/ | ||
public function getCustomerTokensById(string $customerId) | ||
{ | ||
$uri = $this->getOpenApiUrl('v3', "/payment/tokens/$customerId"); | ||
return $this->mapResponse($this->callApi('get', $uri)->send()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace RevenueMonster\SDK\Request; | ||
|
||
use Exception; | ||
use JsonSerializable; | ||
use Rakit\Validation\Validator; | ||
use RevenueMonster\SDK\Exceptions\ValidationException; | ||
|
||
class CustomerOrderAmount implements JsonSerializable | ||
{ | ||
public $currency = 'MYR'; | ||
public $amount = 0; | ||
|
||
public function jsonSerialize() | ||
{ | ||
$data = [ | ||
'currency' => $this->currency, | ||
'amount' => $this->amount, | ||
]; | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace RevenueMonster\SDK\Request; | ||
|
||
use Exception; | ||
use JsonSerializable; | ||
use Rakit\Validation\Validator; | ||
use RevenueMonster\SDK\Exceptions\ValidationException; | ||
|
||
class RecurringCustomer implements JsonSerializable | ||
{ | ||
public $storeId = ''; | ||
public $email = ''; | ||
public $name = ''; | ||
public $countryCode = ''; | ||
public $phoneNumber = ''; | ||
public $productName = ''; | ||
public $productDescription = ''; | ||
public $currency = 'MYR'; | ||
public $amount = 0; | ||
public $redirectUrl = ''; | ||
public $notifyUrl = ''; | ||
public $recurringInterval = ''; | ||
public $recurringTarget = ''; | ||
public $recurringRepetition = 1; | ||
|
||
public function jsonSerialize() | ||
{ | ||
$data = [ | ||
'storeId' => $this->storeId, | ||
'email' => $this->email, | ||
'name' => $this->name, | ||
'countryCode' => $this->countryCode, | ||
'phoneNumber' => $this->phoneNumber, | ||
'productName' => $this->productName, | ||
'productDescription' => $this->productDescription, | ||
'currency' => $this->currency, | ||
'amount' => $this->amount, | ||
'redirectUrl' => escape_url($this->redirectUrl), | ||
'notifyUrl' => escape_url($this->notifyUrl), | ||
'recurringInterval' => $this->recurringInterval, | ||
'recurringTarget' => $this->recurringTarget, | ||
'recurringRepetition' => $this->recurringRepetition, | ||
]; | ||
|
||
$validator = new Validator; | ||
$validation = $validator->make($data, [ | ||
'storeId' => 'required|max:255', | ||
'email' => 'required', | ||
'name' => 'required', | ||
'countryCode' => 'required', | ||
'phoneNumber' => 'required', | ||
'productName' => 'required', | ||
'productDescription' => 'required', | ||
'currency' => 'required', | ||
'amount' => 'required', | ||
'redirectUrl' => 'required|url', | ||
'notifyUrl' => 'required|url', | ||
'recurringInterval' => 'required|in:WEEKLY,MONTHLY', | ||
]); | ||
|
||
$validation->validate(); | ||
|
||
if ($validation->fails()) { | ||
throw new ValidationException($validation->errors()); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace RevenueMonster\SDK\Request; | ||
|
||
use Exception; | ||
use JsonSerializable; | ||
use Rakit\Validation\Validator; | ||
use RevenueMonster\SDK\Exceptions\ValidationException; | ||
|
||
class TokenizedCustomer implements JsonSerializable | ||
{ | ||
public $storeId = ''; | ||
public $email = ''; | ||
public $name = ''; | ||
public $countryCode = ''; | ||
public $phoneNumber = ''; | ||
public $productName = ''; | ||
public $productDescription = ''; | ||
// public $currency = 'MYR'; | ||
// public $amount = 0; | ||
public $redirectUrl = ''; | ||
public $notifyUrl = ''; | ||
|
||
public function jsonSerialize() | ||
{ | ||
$data = [ | ||
'storeId' => $this->storeId, | ||
'email' => $this->email, | ||
'name' => $this->name, | ||
'countryCode' => $this->countryCode, | ||
'phoneNumber' => $this->phoneNumber, | ||
'productName' => $this->productName, | ||
'productDescription' => $this->productDescription, | ||
'redirectUrl' => escape_url($this->redirectUrl), | ||
'notifyUrl' => escape_url($this->notifyUrl), | ||
]; | ||
|
||
$validator = new Validator; | ||
$validation = $validator->make($data, [ | ||
'storeId' => 'required|max:255', | ||
'email' => 'required', | ||
'name' => 'required', | ||
'countryCode' => 'required', | ||
'phoneNumber' => 'required', | ||
'productName' => 'required', | ||
'productDescription' => 'required', | ||
'redirectUrl' => 'required|url', | ||
'notifyUrl' => 'required|url', | ||
]); | ||
|
||
$validation->validate(); | ||
|
||
if ($validation->fails()) { | ||
throw new ValidationException($validation->errors()); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.