Skip to content

Commit

Permalink
Merge pull request #5 from wallee-payment/ss-plenty
Browse files Browse the repository at this point in the history
Ss plenty
  • Loading branch information
schurter-cw authored Oct 23, 2018
2 parents 5a4f45b + 0f16173 commit a3d5c3f
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 181 deletions.
5 changes: 5 additions & 0 deletions meta/documents/changelog_de.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for wallee

## v1.0.13 (2018-10-23)

### Fixed
- Show reason for transaction failure to customer.

## v1.0.12 (2018-10-16)

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions meta/documents/changelog_en.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for wallee

## v1.0.13 (2018-10-23)

### Fixed
- Show reason for transaction failure to customer.

## v1.0.12 (2018-10-16)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"namespace": "Wallee",
"type": "payment",
"version": "1.0.12",
"version": "1.0.13",
"license": " Apache License Version 2",
"isClosedSource" : false,
"pluginIcon" : "icon_plugin_md.png",
Expand Down
355 changes: 185 additions & 170 deletions resources/lib/createTransaction.php

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions resources/lib/getTransactionByMerchantReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
use Wallee\Sdk\Service\TransactionService;
use Wallee\Sdk\Model\EntityQuery;
use Wallee\Sdk\Model\EntityQueryFilter;
use Wallee\Sdk\Model\EntityQueryOrderBy;
use Wallee\Sdk\Model\EntityQueryOrderByType;
use Wallee\Sdk\Model\EntityQueryFilterType;
use Wallee\Sdk\Model\CriteriaOperator;

require_once __DIR__ . '/WalleeSdkHelper.php';

$client = WalleeSdkHelper::getApiClient(SdkRestApi::getParam('gatewayBasePath'), SdkRestApi::getParam('apiUserId'), SdkRestApi::getParam('apiUserKey'));

$spaceId = SdkRestApi::getParam('spaceId');

$service = new TransactionService($client);
$query = new EntityQuery();
$filter = new EntityQueryFilter();
$filter->setType(EntityQueryFilterType::LEAF);
$filter->setOperator(CriteriaOperator::EQUALS);
$filter->setFieldName('merchantReference');
$filter->setValue(SdkRestApi::getParam('merchantReference'));
$query->setFilter($filter);
$orderBy = new EntityQueryOrderBy();
$orderBy->setFieldName('createdOn');
$orderBy->setSorting(EntityQueryOrderByType::DESC);
$query->setOrderBys($orderBy);
$query->setNumberOfEntities(1);
$transactions = $service->search($spaceId, $query);

return WalleeSdkHelper::convertData(current($transactions));
71 changes: 71 additions & 0 deletions src/Controllers/PaymentProcessController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
namespace Wallee\Controllers;

use IO\Services\NotificationService;
use Plenty\Plugin\Controller;
use Plenty\Plugin\Http\Request;
use Plenty\Plugin\Http\Response;
use Plenty\Plugin\Log\Loggable;
use Wallee\Services\WalleeSdkService;

class PaymentProcessController extends Controller
{

use Loggable;

/**
*
* @var Request
*/
private $request;

/**
*
* @var Response
*/
private $response;

/**
*
* @var WalleeSdkService
*/
private $sdkService;

/**
*
* @var NotificationService
*/
private $notificationService;

/**
* PaymentController constructor.
*
* @param Request $request
* @param Response $response
* @param WalleeSdkService $sdkService
* @param NotificationService $notificationService
*/
public function __construct(Request $request, Response $response, WalleeSdkService $sdkService, NotificationService $notificationService)
{
parent::__construct();
$this->request = $request;
$this->response = $response;
$this->sdkService = $sdkService;
$this->notificationService = $notificationService;
}

/**
*
* @param int $id
*/
public function failTransaction(int $id)
{
$transaction = $this->sdkService->call('getTransactionByMerchantReference', [
'merchantReference' => $id
]);
if (is_array($transaction) && ! isset($transaction['error']) && isset($transaction['userFailureMessage']) && ! empty($transaction['userFailureMessage'])) {
$this->notificationService->error($transaction['userFailureMessage']);
}
return $this->response->redirectTo('checkout');
}
}
21 changes: 11 additions & 10 deletions src/Providers/WalleeRouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

namespace Wallee\Providers;

use Plenty\Plugin\RouteServiceProvider;
use Plenty\Plugin\Routing\Router;

class WalleeRouteServiceProvider extends RouteServiceProvider {

/**
*
* @param Router $router
*/
public function map(Router $router) {
$router->post('wallee/update-transaction', 'Wallee\Controllers\PaymentNotificationController@updateTransaction');
}
class WalleeRouteServiceProvider extends RouteServiceProvider
{

/**
*
* @param Router $router
*/
public function map(Router $router)
{
$router->post('wallee/update-transaction', 'Wallee\Controllers\PaymentNotificationController@updateTransaction');
$router->get('wallee/fail-transaction/{id}', 'Wallee\Controllers\PaymentProcessController@failTransaction')->where('id', '\d+');
}
}
10 changes: 10 additions & 0 deletions src/Services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function getPaymentContent(Basket $basket, PaymentMethod $paymentMethod):
'language' => $this->session->getLocaleSettings()->language,
'successUrl' => $this->getSuccessUrl(),
'failedUrl' => $this->getFailedUrl(),
'checkoutUrl' => $this->getCheckoutUrl(),
'showNetPrice' => $this->session->getCustomer()->showNetPrice
];

Expand Down Expand Up @@ -306,6 +307,15 @@ private function getSuccessUrl(): string
* @return string
*/
private function getFailedUrl(): string
{
return $this->webstoreHelper->getCurrentWebstoreConfiguration()->domainSsl . '/wallee/fail-transaction';
}

/**
*
* @return string
*/
private function getCheckoutUrl(): string
{
return $this->webstoreHelper->getCurrentWebstoreConfiguration()->domainSsl . '/checkout';
}
Expand Down

0 comments on commit a3d5c3f

Please sign in to comment.