-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,434 additions
and
789 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "src/engine/Library/paymentwall"] | ||
path = src/engine/Library/paymentwall | ||
url = git@github.com:paymentwall/paymentwall-php.git | ||
[submodule "src/Paymentwall/Components/Libs/Paymentwall"] | ||
path = src/Paymentwall/Components/Libs/Paymentwall | ||
url = https://github.com/paymentwall/paymentwall-php.git |
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
Submodule Paymentwall
added at
040cbd
65 changes: 65 additions & 0 deletions
65
src/Paymentwall/Components/Services/DeliveryConfirmationService.php
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,65 @@ | ||
<?php | ||
|
||
namespace Paymentwall\Components\Services; | ||
|
||
use Paymentwall_GenerericApiObject; | ||
use Shopware\Models\Order\Order; | ||
|
||
class DeliveryConfirmationService | ||
{ | ||
const PRODUCT_PHYSICAL = 'physical'; | ||
const PRODUCT_DIGITAL = 'digital'; | ||
const STATUS_DELIVERED = 'delivered'; | ||
const STATUS_ORDER_PLACED = 'order_placed'; | ||
const STATUS_ORDER_SHIPPED = 'order_shipped'; | ||
|
||
/** | ||
* @var Order $order | ||
* @param $customer | ||
* @param $status | ||
* @param null $trackingData | ||
* @return array | ||
*/ | ||
public function prepareDeliveryData($order, $status, $trackingData = null) | ||
{ | ||
$shipping = $order->getShipping(); | ||
$data = [ | ||
'payment_id' => $order->getTransactionId(), | ||
'merchant_reference_id' => $order->getId(), | ||
'type' => ($order->getEsd()) ? self::PRODUCT_DIGITAL : self::PRODUCT_PHYSICAL, | ||
'status' => $status, | ||
'estimated_delivery_datetime' => date('Y/m/d H:i:s'), | ||
'estimated_update_datetime' => date('Y/m/d H:i:s'), | ||
'refundable' => 'yes', | ||
'details' => 'Order status has been updated on ' . date('Y/m/d H:i:s'), | ||
'product_description' => '', | ||
'shipping_address[country]' => $shipping->getCountry()->getIso(), | ||
'shipping_address[city]' => $shipping->getCountry(), | ||
'shipping_address[zip]' => $shipping->getZipCode(), | ||
'shipping_address[state]' => !empty($shipping->getState()) ? $shipping->getState() : 'N/A', | ||
'shipping_address[street]' => $shipping->getStreet(), | ||
'shipping_address[phone]' => !empty($shipping->getPhone()) ? $shipping->getPhone() : 'N/A', | ||
'shipping_address[firstname]' => $shipping->getFirstName(), | ||
'shipping_address[lastname]' => $shipping->getLastName(), | ||
'shipping_address[email]' => $order->getCustomer()->getEmail(), | ||
'reason' => 'none', | ||
'attachments' => null, | ||
'is_test' => PaymentwallSettings::getTestMode(), | ||
]; | ||
|
||
if (!empty($trackingData)) { | ||
return array_merge($data, $trackingData); | ||
} | ||
return $data; | ||
} | ||
|
||
public function sendDeliveryData($dataPrepared) | ||
{ | ||
if (empty($dataPrepared)) { | ||
return; | ||
} | ||
|
||
$delivery = new Paymentwall_GenerericApiObject('delivery'); | ||
$delivery->post($dataPrepared); | ||
} | ||
} |
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,103 @@ | ||
<?php | ||
|
||
namespace Paymentwall\Components\Services; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Shopware\Models\Order\Order; | ||
use Shopware\Models\Order\Status; | ||
|
||
class OrderService | ||
{ | ||
protected $connection; | ||
|
||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
public function setOrderStatus($orderId, $orderStatusId) | ||
{ | ||
return $this->connection->createQueryBuilder() | ||
->update('s_order') | ||
->set('status', ':orderStatusId') | ||
->where('id = :orderId') | ||
->setParameters([ | ||
':orderId' => $orderId, | ||
':orderStatusId' => $orderStatusId, | ||
]) | ||
->execute(); | ||
} | ||
|
||
public function getOrderStatus($orderId) | ||
{ | ||
return $this->connection->createQueryBuilder() | ||
->select('status') | ||
->from('s_order') | ||
->where('id = :orderId') | ||
->setParameters([ | ||
':orderId' => $orderId | ||
]) | ||
->execute() | ||
->fetchColumn(); | ||
} | ||
|
||
public function isOrderHistoryEmpty($orderId) | ||
{ | ||
return !$this->connection->createQueryBuilder() | ||
->select('id') | ||
->from('s_order_history') | ||
->where('orderId = :orderId') | ||
->setParameters([ | ||
':orderId' => $orderId, | ||
]) | ||
->execute() | ||
->fetchColumn(); | ||
} | ||
|
||
public function updateTransactionId($transactionId, $orderId) | ||
{ | ||
return $this->connection->createQueryBuilder() | ||
->update('s_order') | ||
->set('transactionID', ':transactionId') | ||
->where('id = :orderId') | ||
->setParameters([ | ||
':orderId' => $orderId, | ||
':transactionId' => $transactionId, | ||
]) | ||
->execute(); | ||
} | ||
|
||
public function getPaymentIdByOrderId($orderId) | ||
{ | ||
return $this->connection->createQueryBuilder() | ||
->select('paymentID') | ||
->from('s_order') | ||
->where('id = :orderId') | ||
->setParameters([ | ||
':orderId' => $orderId, | ||
]) | ||
->execute() | ||
->fetchColumn(); | ||
} | ||
|
||
public function loadOrderRepositoryById($orderId) | ||
{ | ||
$repository = Shopware()->Models()->getRepository(Order::class); | ||
return $repository->find($orderId); | ||
} | ||
|
||
public function checkOrderWasPaid($orderId) | ||
{ | ||
return $this->connection->createQueryBuilder() | ||
->select('id') | ||
->from('s_order_history') | ||
->where('orderId = :orderId') | ||
->andWhere('payment_status_id = :payment_status_id') | ||
->setParameters([ | ||
':orderId' => $orderId, | ||
':payment_status_id' => Status::PAYMENT_STATE_COMPLETELY_PAID | ||
]) | ||
->execute() | ||
->fetchColumn(); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Paymentwall\Components\Services; | ||
|
||
use Paymentwall_Product; | ||
use Paymentwall_Widget; | ||
use Shopware\Models\Order\Order; | ||
|
||
class PaymentService | ||
{ | ||
public function prepareWidget($user, $totalAmount, $currencyCode, $orderId) | ||
{ | ||
$session = Shopware()->Container()->get('session'); | ||
$selectedPaymentMethod = $session->offsetGet('paymentwall-localpayment'); | ||
|
||
return new Paymentwall_Widget( | ||
!empty($user['userID']) ? $user['userID'] : $user['email'], | ||
PaymentwallSettings::getWidgetCode(), | ||
[ | ||
new Paymentwall_Product( | ||
$orderId, | ||
$totalAmount, | ||
$currencyCode, | ||
Paymentwall_Product::TYPE_FIXED | ||
) | ||
], | ||
[ | ||
'integration_module' => 'shopware', | ||
'ps' => !empty($selectedPaymentMethod['id']) ? $selectedPaymentMethod['id'] : 'all', | ||
'test_mode' => PaymentwallSettings::getTestMode(), | ||
'success_url' => $this->getSuccessUrl() | ||
] | ||
); | ||
} | ||
|
||
protected function getSuccessUrl() | ||
{ | ||
$router = Shopware()->Front()->Router(); | ||
return $router->assemble(['controller' => 'Paymentwall', 'action' => 'success']); | ||
} | ||
|
||
public function getOrderIdByPaymentUniqueId($paymentUniqueId) | ||
{ | ||
$repository = Shopware()->Models()->getRepository(Order::class); | ||
$order = $repository->findOneBy([ | ||
'temporaryId' => $paymentUniqueId, | ||
'transactionId' => $paymentUniqueId | ||
]); | ||
return $order->getId(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Paymentwall/Components/Services/PaymentSystemService.php
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,67 @@ | ||
<?php | ||
|
||
namespace Paymentwall\Components\Services; | ||
|
||
use Paymentwall_Config; | ||
use Paymentwall_Signature_Widget; | ||
|
||
class PaymentSystemService | ||
{ | ||
public function getLocalPaymentMethods() | ||
{ | ||
$localPaymentMethods = []; | ||
|
||
if (empty($localPaymentMethods)) { | ||
$userCountry = UtilService::getCountryByIp(UtilService::getRealClientIP()); | ||
$response = $this->getPaymentMethodFromApi($userCountry); | ||
$localPaymentMethods = $this->prepareLocalPayment($response); | ||
} | ||
return $localPaymentMethods; | ||
} | ||
|
||
protected function getPaymentMethodFromApi($userCountry) | ||
{ | ||
if (empty($userCountry)) { | ||
return null; | ||
} | ||
|
||
$params = array( | ||
'key' => PaymentwallSettings::getProjectKey(), | ||
'country_code' => $userCountry, | ||
'sign_version' => 3, | ||
'currencyCode' => Shopware()->Container()->get('currency')->getShortName(), | ||
); | ||
|
||
$params['sign'] = (new Paymentwall_Signature_Widget())->calculate( | ||
$params, | ||
$params['sign_version'] | ||
); | ||
|
||
$url = Paymentwall_Config::API_BASE_URL . '/payment-systems/?' . http_build_query($params); | ||
$curl = curl_init($url); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
$response = curl_exec($curl); | ||
if (curl_error($curl)) { | ||
return null; | ||
} | ||
|
||
return json_decode($response, true); | ||
} | ||
|
||
protected function prepareLocalPayment($payments) | ||
{ | ||
$methods = []; | ||
if (!empty($payments)) { | ||
foreach ($payments as $payment) { | ||
if (!empty($payment['id']) && !empty($payment['name'])) { | ||
$methods[] = [ | ||
'id' => $payment['id'], | ||
'name' => $payment['name'], | ||
'img_url' => !empty($payment['img_url']) ? $payment['img_url'] : '' | ||
]; | ||
} | ||
} | ||
} | ||
return $methods; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Paymentwall/Components/Services/PaymentwallSettings.php
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,47 @@ | ||
<?php | ||
|
||
namespace Paymentwall\Components\Services; | ||
|
||
class PaymentwallSettings | ||
{ | ||
protected static function getConfig() | ||
{ | ||
return Shopware()->Container()->get('shopware.plugin.cached_config_reader')->getByPluginName('paymentwall'); | ||
} | ||
|
||
public static function getTestMode() | ||
{ | ||
$config = self::getConfig(); | ||
return $config['pwTestMode']; | ||
} | ||
|
||
public static function getWidgetCode() | ||
{ | ||
$config = self::getConfig(); | ||
return $config['pwWidget']; | ||
} | ||
|
||
public static function getProjectKey() | ||
{ | ||
$config = self::getConfig(); | ||
return $config['pwProjectKey']; | ||
} | ||
|
||
public static function getSecretKey() | ||
{ | ||
$config = self::getConfig(); | ||
return $config['pwWipwSecretKey']; | ||
} | ||
|
||
public static function getRefundState() | ||
{ | ||
$config = self::getConfig(); | ||
return $config['pwRefundState']; | ||
} | ||
|
||
public static function getRedirectPayment() | ||
{ | ||
$config = self::getConfig(); | ||
return $config['pwRedirectPayment']; | ||
} | ||
} |
Oops, something went wrong.