|
@@ 487-518 (lines=32) @@
|
| 484 |
|
* @param string $amount [Mandatory] |
| 485 |
|
* @param string $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]] |
| 486 |
|
*/ |
| 487 |
|
public function addPayment(string $reference_code = null, string $date = null, string $amount = null, string $channel = null){ |
| 488 |
|
if(!$reference_code || $reference_code === null){ |
| 489 |
|
throw new IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code"); |
| 490 |
|
} |
| 491 |
|
|
| 492 |
|
if(!$due_date || $due_date === null){ |
| 493 |
|
throw new IsNullOrInvalid("Error Processing Request - Null/Invalid date"); |
| 494 |
|
} |
| 495 |
|
|
| 496 |
|
if(!$amount || $amount === null){ |
| 497 |
|
throw new IsNullOrInvalid("Error Processing Request - Null/Invalid amount"); |
| 498 |
|
} |
| 499 |
|
|
| 500 |
|
$valid_channels = ["Cash", "BankTransfer", "POS", "Cheque"]; |
| 501 |
|
|
| 502 |
|
if(!$channel || $channel === null){ |
| 503 |
|
throw new IsNull("Error Processing Request - Null/Invalid amount"); |
| 504 |
|
}elseif (!in_array(ucfirst($channel), $valid_channels)) { |
| 505 |
|
throw new IsInvalid("Invalid Channel - Cash, BankTransfer, POS or Cheque"); |
| 506 |
|
} |
| 507 |
|
|
| 508 |
|
$url = "/payments"; |
| 509 |
|
|
| 510 |
|
$post_data = [ |
| 511 |
|
'reference_code' => $reference_code, |
| 512 |
|
'date' => $date, |
| 513 |
|
'amount' => $amount, |
| 514 |
|
'channel' => $channel |
| 515 |
|
]; |
| 516 |
|
|
| 517 |
|
return $this->sendRequest('post', $url, ['form_params' => $post_data]); |
| 518 |
|
} |
| 519 |
|
|
| 520 |
|
|
| 521 |
|
|
|
@@ 589-621 (lines=33) @@
|
| 586 |
|
* @param string $unit_cost [Mandatory - Product's unit cost] |
| 587 |
|
* @param string $type [Mandatory - Product type 'product' or 'service'] |
| 588 |
|
*/ |
| 589 |
|
public function addProduct(string $name = null, string $description = null, string $unit_cost = null, string $type = null){ |
| 590 |
|
if(!$name || $name === null){ |
| 591 |
|
throw new IsNull("Error Processing Request - Null/Invalid name"); |
| 592 |
|
} |
| 593 |
|
|
| 594 |
|
if(!$description || $description === null){ |
| 595 |
|
throw new IsNull("Error Processing Request - Null/Invalid description"); |
| 596 |
|
} |
| 597 |
|
|
| 598 |
|
if(!$unit_cost || $unit_cost === null){ |
| 599 |
|
throw new IsNull("Error Processing Request - Null/Invalid unit_cost"); |
| 600 |
|
} |
| 601 |
|
|
| 602 |
|
//Validate Product Type |
| 603 |
|
$valid_product_type = ["product", "service"]; |
| 604 |
|
|
| 605 |
|
if(!$type || $type === null){ |
| 606 |
|
throw new IsNull("Error Processing Request - Null/Invalid type"); |
| 607 |
|
}elseif (!in_array(strtolower($type), $valid_product_type)) { |
| 608 |
|
throw new IsInvalid("Invalid Type - Available options: 'product' or 'service'"); |
| 609 |
|
} |
| 610 |
|
|
| 611 |
|
$url = "/products"; |
| 612 |
|
|
| 613 |
|
$post_data = [ |
| 614 |
|
'name' => $name, |
| 615 |
|
'description' => $description, |
| 616 |
|
'unit_cost' => $unit_cost, |
| 617 |
|
'type' => $type |
| 618 |
|
]; |
| 619 |
|
|
| 620 |
|
return $this->sendRequest('post', $url, ['form_params' => $post_data]); |
| 621 |
|
} |
| 622 |
|
|
| 623 |
|
|
| 624 |
|
|