Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
commerce_winbank_redirect
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
commerce_winbank_redirect
Commits
8bcf2900
Commit
8bcf2900
authored
Apr 11, 2019
by
GiorgosK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add offsite redirect WinbankPaymentRedirectForm
parent
0a3e26ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
0 deletions
+116
-0
src/PluginForm/OffsiteRedirect/WinbankPaymentRedirectForm.php
...PluginForm/OffsiteRedirect/WinbankPaymentRedirectForm.php
+116
-0
No files found.
src/PluginForm/OffsiteRedirect/WinbankPaymentRedirectForm.php
0 → 100644
View file @
8bcf2900
<?php
namespace
Drupal\commerce_winbank\PluginForm\OffsiteRedirect
;
use
Drupal\commerce_payment
\
Exception\InvalidResponseException
;
use
Drupal\commerce_payment
\
Exception\PaymentGatewayException
;
use
Drupal\commerce_payment
\
PluginForm\PaymentOffsiteForm
as
BasePaymentOffsiteForm
;
use
Drupal\Core\Form\FormStateInterface
;
class
WinbankPaymentRedirectForm
extends
BasePaymentOffsiteForm
{
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
=
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
$payment
=
$this
->
entity
;
$payment_gateway_plugin
=
$payment
->
getPaymentGateway
()
->
getPlugin
();
$config
=
$payment_gateway_plugin
->
getConfiguration
();
$order
=
$payment
->
getOrder
();
// Format amount
$amount
=
sprintf
(
'%0.2f'
,
$order
->
getTotalPrice
()
->
getNumber
());
if
(
$config
[
'mode'
]
==
'test'
)
{
$config
[
"tickets_url"
]
=
$config
[
"tickets_url_test"
];
$config
[
"paycenter_url"
]
=
$config
[
"paycenter_url_test"
];
}
// Validate merchant_id, other validations ?
if
(
empty
(
$config
[
'merchant_id'
]))
{
throw
new
PaymentGatewayException
(
'Merchant ID not provided.'
);
}
// Get new ticket
try
{
$result
=
$this
->
getNewTicket
(
$amount
,
$order
->
id
(),
$config
);
if
(
$result
->
IssueNewTicketResult
->
ResultCode
==
0
)
{
// save response data for validating response later
$order
->
setData
(
"IssueNewTicketResult"
,[
"ResultCode"
=>
$result
->
IssueNewTicketResult
->
ResultCode
,
"TranTicket"
=>
$result
->
IssueNewTicketResult
->
TranTicket
,
"Timestamp"
=>
$result
->
IssueNewTicketResult
->
Timestamp
,
"MinutesToExpiration"
=>
$result
->
IssueNewTicketResult
->
MinutesToExpiration
,
]);
}
else
{
$message
=
'There was a problem connecting ot the ticket issuer: '
.
$result
->
IssueNewTicketResult
->
ResultDescription
;
throw
new
InvalidResponseException
(
$message
);
}
}
catch
(
Exception
$e
)
{
throw
new
InvalidResponseException
(
'Could not connect to bank ticket issuer'
);
}
// Prepare redirect form
$data
=
[
'AcquirerId'
=>
$config
[
'acquirer_id'
],
'MerchantId'
=>
$config
[
'merchant_id'
],
'PosId'
=>
$config
[
'pos_id'
],
'User'
=>
$config
[
'user'
],
'MerchantReference'
=>
$order
->
id
(),
'LanguageCode'
=>
$config
[
'language_code'
],
'ParamBackLink'
=>
''
,
];
$form
=
$this
->
buildRedirectForm
(
$form
,
$form_state
,
$config
[
'paycenter_url'
],
$data
);
//temporary
unset
(
$form
[
'#attached'
][
'library'
]);
return
$form
;
}
/**
* Soap request to get NewTicket for transaction
*
* @param int $amount
* The order amount.
* @param int $orderid
* The order id.
* @param int $config
* The configuration object.
*
* @return array
* Object containing the soap service response.
*
*/
public
function
getNewTicket
(
$amount
,
$orderid
,
$config
){
//libxml_disable_entity_loader(false);
$options
=
array
(
'location'
=>
$config
[
'tickets_url'
],
'uri'
=>
$config
[
'tickets_url'
]
);
$soap
=
new
\
SoapClient
(
NULL
,
$options
);
$ticketRequest
=
[
'Username'
=>
$config
[
'username'
],
'Password'
=>
hash
(
'md5'
,
$config
[
'password'
]),
'MerchantId'
=>
$config
[
'merchant_id'
],
'PosId'
=>
$config
[
'pos_id'
],
'AcquirerId'
=>
$config
[
'acquirer_id'
],
'MerchantReference'
=>
$orderid
,
'RequestType'
=>
$config
[
'request_type'
],
'ExpirePreauth'
=>
0
,
'Amount'
=>
$amount
,
'CurrencyCode'
=>
$config
[
'currency_code'
],
'Installments'
=>
0
,
'Bnpl'
=>
'0'
,
'Parameters'
=>
''
];
$xml
=
array
(
'Request'
=>
$ticketRequest
);
return
$soap
->
IssueNewTicket
(
$xml
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment