-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add craftgate payment orchestration prestashop module (#1)
- Loading branch information
1 parent
ea5e264
commit 141c8e7
Showing
55 changed files
with
2,636 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
.DS_Store |
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,68 @@ | ||
# Craftgate Payment Orchestration Module for PrestaShop | ||
|
||
## Description | ||
|
||
The Craftgate Payment Orchestration module for PrestaShop provides a seamless integration with Craftgate's payment services. It allows your customers to make payments using various methods supported by Craftgate, including credit/debit cards and alternative payment methods. | ||
|
||
## Features | ||
|
||
- Easy integration with Craftgate payment services | ||
- Support for credit/debit card payments | ||
- Support for alternative payment methods | ||
- Customizable payment option title and description | ||
- Sandbox mode for testing | ||
- One-page checkout option | ||
|
||
## Compatibility | ||
|
||
This module is compatible with PrestaShop versions 1.7.x and 8.x. | ||
|
||
## Requirements | ||
|
||
- PHP 7.2 or higher | ||
- PrestaShop 1.7.x or 8.x | ||
|
||
## Installation | ||
|
||
There are two ways to install the Craftgate Payment Orchestration module: | ||
|
||
### Method 1: Manual Installation | ||
|
||
1. Download the latest release of the module from the GitHub repository. | ||
2. Unzip the downloaded file. | ||
3. Upload the `craftgate_payment_orchestration` folder to your PrestaShop's `/modules` directory. | ||
4. Log in to your PrestaShop admin panel. | ||
5. Navigate to "Modules" > "Module Manager". | ||
6. Search for "Craftgate Payment Orchestration" in the module list. | ||
7. Click on the "Install" button next to the module. | ||
8. After installation, click on "Configure" to set up your Craftgate API credentials and other settings. | ||
|
||
### Method 2: ZIP File Installation | ||
|
||
1. Download the ZIP file from the Github repository. | ||
2. Log in to your PrestaShop admin panel. | ||
3. Navigate to "Modules" > "Module Manager". | ||
4. Click on the "Upload a module" button at the top of the page. | ||
5. Select the downloaded ZIP file and upload it. | ||
6. PrestaShop will automatically install the module. | ||
7. After installation, click on "Configure" to set up your Craftgate API credentials and other settings. | ||
|
||
## Configuration | ||
|
||
1. In the module configuration page, enter your Craftgate API credentials (API Key and Secret Key) for both live and sandbox environments. | ||
2. Choose whether to enable sandbox mode for testing. | ||
3. Customize the payment option title and description if desired. | ||
4. Configure the one-page checkout option if you want to use it. | ||
5. Save your settings. | ||
|
||
## Usage | ||
|
||
Once installed and configured, the Craftgate payment option will appear on the checkout page for your customers. They can select this option to pay using Craftgate's services. | ||
|
||
## Support | ||
|
||
For any issues or questions, please contact Craftgate support via [email protected] | ||
|
||
## License | ||
|
||
This module is released under the [MIT License](LICENSE). |
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,46 @@ | ||
<?php | ||
|
||
require_once _PS_MODULE_DIR_ . 'craftgate_payment_orchestration/lib/craftgate/autoload.php'; | ||
|
||
class CraftgateClient | ||
{ | ||
private static ?CraftgateClient $instance = null; | ||
private \Craftgate\Craftgate $craftgate; | ||
|
||
|
||
public static function getInstance($api_key, $secret_key, $api_url): CraftgateClient | ||
{ | ||
if (!self::$instance) { | ||
self::$instance = new CraftgateClient($api_key, $secret_key, $api_url); | ||
} | ||
return self::$instance; | ||
|
||
} | ||
|
||
private function __construct($api_key, $secret_key, $api_url) | ||
{ | ||
$this->craftgate = new \Craftgate\Craftgate(array( | ||
'apiKey' => $api_key, | ||
'secretKey' => $secret_key, | ||
'baseUrl' => $api_url, | ||
)); | ||
} | ||
|
||
public function initCheckoutForm($request) | ||
{ | ||
$response = $this->craftgate->payment()->initCheckoutPayment($request); | ||
return $this->buildResponse($response); | ||
} | ||
|
||
public function retrieveCheckoutFormResult($token) | ||
{ | ||
$response = $this->craftgate->payment()->retrieveCheckoutPayment($token); | ||
return $this->buildResponse($response); | ||
} | ||
|
||
private function buildResponse($response) | ||
{ | ||
$response_json = json_decode($response); | ||
return $response_json->data ?? $response_json; | ||
} | ||
} |
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,96 @@ | ||
<?php | ||
|
||
namespace classes; | ||
|
||
use Db; | ||
use ObjectModel; | ||
|
||
class CraftgatePayment extends ObjectModel | ||
{ | ||
public string $id_craftgate_payment; | ||
public $checkout_token; | ||
public $payment_id; | ||
public $meta_data; | ||
public $id_order; | ||
|
||
public static $definition = [ | ||
'table' => 'craftgate_payments', | ||
'primary' => 'id_craftgate_payment', | ||
'fields' => [ | ||
'payment_id' => ['type' => self::TYPE_INT, 'required' => true], | ||
'checkout_token' => ['type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 255], | ||
'meta_data' => ['type' => self::TYPE_STRING], | ||
'id_order' => ['type' => self::TYPE_INT, 'required' => true], | ||
], | ||
]; | ||
|
||
public static function getByOrderId(int $orderId) | ||
{ | ||
$sql = 'SELECT `id_craftgate_payment` | ||
FROM `' . _DB_PREFIX_ . 'craftgate_payments` | ||
WHERE `id_order` = ' . $orderId; | ||
|
||
$result = Db::getInstance()->getValue($sql); | ||
return !empty($result) ? new self($result) : false; | ||
} | ||
|
||
public static function getByCheckoutToken(string $checkoutToken): false|CraftgatePayment | ||
{ | ||
$sql = 'SELECT `id_craftgate_payment` | ||
FROM `' . _DB_PREFIX_ . 'craftgate_payments` | ||
WHERE `checkout_token` = \'' . pSQL($checkoutToken) . '\''; | ||
|
||
$result = Db::getInstance()->getValue($sql); | ||
return !empty($result) ? new self($result) : false; | ||
} | ||
|
||
public function getIdOrder() | ||
{ | ||
return $this->id_order; | ||
} | ||
|
||
public function setIdOrder($id_order): void | ||
{ | ||
$this->id_order = $id_order; | ||
} | ||
|
||
public function getPaymentId() | ||
{ | ||
return $this->payment_id; | ||
} | ||
|
||
public function setPaymentId($payment_id): void | ||
{ | ||
$this->payment_id = $payment_id; | ||
} | ||
|
||
public function getCheckoutToken() | ||
{ | ||
return $this->checkout_token; | ||
} | ||
|
||
public function setCheckoutToken($checkout_token): void | ||
{ | ||
$this->checkout_token = $checkout_token; | ||
} | ||
|
||
public function getIdCraftgatePayment(): string | ||
{ | ||
return $this->id_craftgate_payment; | ||
} | ||
|
||
public function setIdCraftgatePayment(string $id_craftgate_payment): void | ||
{ | ||
$this->id_craftgate_payment = $id_craftgate_payment; | ||
} | ||
|
||
public function getMetaData() | ||
{ | ||
return json_decode($this->meta_data); | ||
} | ||
|
||
public function setMetaData($data): void | ||
{ | ||
$this->meta_data = json_encode($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,24 @@ | ||
<?php | ||
|
||
namespace classes; | ||
use Db; | ||
|
||
class CraftgatePaymentDBManager | ||
{ | ||
|
||
public static function install(): bool | ||
{ | ||
$sql = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'craftgate_payments` ( | ||
`id_craftgate_payment` INT AUTO_INCREMENT PRIMARY KEY, | ||
`checkout_token` VARCHAR(255) NULL, | ||
`payment_id` BIGINT NOT NULL, | ||
`meta_data` MEDIUMTEXT NULL, | ||
`id_order` INT UNSIGNED NOT NULL, | ||
FOREIGN KEY (`id_order`) REFERENCES `' . _DB_PREFIX_ . 'orders` (`id_order`) ON DELETE CASCADE | ||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;'; | ||
|
||
return Db::getInstance()->execute($sql); | ||
} | ||
} | ||
|
||
|
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,10 @@ | ||
<?php | ||
|
||
class CraftgatePaymentErrorException extends Exception | ||
{ | ||
|
||
public function __construct(string $message = "", int $code = 0, Throwable $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
Oops, something went wrong.