Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commerce_datatrans-3507218
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
commerce_datatrans-3507218
Commits
bca0202f
Commit
bca0202f
authored
8 years ago
by
András Czövek
Committed by
Sascha Grossenbacher
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2627158
by czigor: Test/production environment switcher
parent
a2d3c41a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
commerce_datatrans.install
+30
-1
30 additions, 1 deletion
commerce_datatrans.install
commerce_datatrans.module
+45
-13
45 additions, 13 deletions
commerce_datatrans.module
with
75 additions
and
14 deletions
commerce_datatrans.install
+
30
−
1
View file @
bca0202f
...
...
@@ -23,4 +23,33 @@ function commerce_datatrans_requirements($phase) {
}
return
$requirements
;
}
\ No newline at end of file
}
/**
* Update all Datatrans payment method rules to use the new "Environment"
* setting.
*/
function
commerce_datatrans_update_7001
()
{
// Get all payment methods.
$conditions
=
array
(
'event'
=>
'commerce_payment_methods'
,
'plugin'
=>
'reaction rule'
,
'active'
=>
TRUE
);
$payment_rules
=
entity_load
(
'rules_config'
,
FALSE
,
$conditions
);
foreach
(
$payment_rules
as
$payment_rule
)
{
foreach
(
rules_config_load
(
$payment_rule
->
name
)
->
actions
()
as
$action
)
{
// This is a datatrans payment method.
if
(
isset
(
$action
->
settings
)
&&
isset
(
$action
->
settings
[
'payment_method'
])
&&
isset
(
$action
->
settings
[
'payment_method'
][
'method_id'
])
&&
$action
->
settings
[
'payment_method'
][
'method_id'
]
==
'commerce_datatrans'
)
{
if
(
isset
(
$action
->
settings
[
'payment_method'
][
'settings'
][
'up_start_url'
]))
{
// The payment method was in 'Test' mode.
if
(
strpos
(
$action
->
settings
[
'payment_method'
][
'settings'
][
'up_start_url'
],
'pilot'
)
!==
FALSE
)
{
$action
->
settings
[
'payment_method'
][
'settings'
][
'environment'
]
=
'test'
;
}
// The payment method was in 'Production' mode.
else
{
$action
->
settings
[
'payment_method'
][
'settings'
][
'environment'
]
=
'prod'
;
}
unset
(
$action
->
settings
[
'payment_method'
][
'settings'
][
'up_start_url'
]);
$payment_rule
->
save
();
}
}
}
}
}
This diff is collapsed.
Click to expand it.
commerce_datatrans.module
+
45
−
13
View file @
bca0202f
<?php
// Test and production request urls and javascripts.
define
(
'COMMERCE_DATATRANS_START_URL_TEST'
,
'https://pilot.datatrans.biz/upp/jsp/upStart.jsp'
);
define
(
'COMMERCE_DATATRANS_START_URL_PROD'
,
'https://payment.datatrans.biz/upp/jsp/upStart.jsp'
);
define
(
'COMMERCE_DATATRANS_SCRIPT_URL_TEST'
,
'https://pilot.datatrans.biz/upp/payment/js/datatrans-1.0.2.js'
);
define
(
'COMMERCE_DATATRANS_SCRIPT_URL_PROD'
,
'https://payment.datatrans.biz/upp/payment/js/datatrans-1.0.2.js'
);
define
(
'COMMERCE_DATATRANS_SETTLEMENT_URL_TEST'
,
'https://pilot.datatrans.biz/upp/jsp/XML_processor.jsp'
);
define
(
'COMMERCE_DATATRANS_SETTLEMENT_URL_PROD'
,
'https://payment.datatrans.biz/upp/jsp/XML_processor.jsp'
);
/**
* @file
* Process payments using Datatrans Payment Page.
...
...
@@ -55,7 +63,7 @@ function commerce_datatrans_settings_form($settings = NULL) {
$settings
+=
array
(
'merchant_id'
=>
'1000011011'
,
'
up_start_url'
=>
'https://pilot.datatrans.biz/upp/jsp/upStart.jsp
'
,
'
environment'
=>
'test
'
,
'req_type'
=>
'CAA'
,
'payment_mode'
=>
'redirect'
,
'security'
=>
array
(),
...
...
@@ -79,10 +87,14 @@ function commerce_datatrans_settings_form($settings = NULL) {
'#required'
=>
TRUE
,
);
$form
[
'up_start_url'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Start URL'
),
'#default_value'
=>
$settings
[
'up_start_url'
],
$form
[
'environment'
]
=
array
(
'#type'
=>
'radios'
,
'#title'
=>
t
(
'Environment'
),
'#options'
=>
array
(
'test'
=>
t
(
'Test'
),
'prod'
=>
t
(
'Production'
),
),
'#default_value'
=>
$settings
[
'environment'
],
'#required'
=>
TRUE
);
...
...
@@ -225,7 +237,7 @@ function commerce_datatrans_redirect_form($form, &$form_state, $order, $payment_
$total
=
field_get_items
(
'commerce_order'
,
$order
,
'commerce_order_total'
);
// Datatrans get default gateway.
$form
[
'#action'
]
=
$payment_method
[
'settings'
][
'up_start_url'
]
;
$form
[
'#action'
]
=
_commerce_datatrans_get_url
(
$payment_method
,
'START'
)
;
// MerchantId, mandatory.
$form
[
'merchantId'
]
=
array
(
...
...
@@ -509,7 +521,7 @@ function commerce_datatrans_submit_form($payment_method, $pane_values, $checkout
'#attached'
=>
array
(
'js'
=>
array
(
array
(
'data'
=>
'https://pilot.datatrans.biz/upp/payment/js/datatrans-1.0.0.js'
,
'data'
=>
_commerce_datatrans_get_url
(
$payment_method
,
'SCRIPT'
)
,
'type'
=>
'external'
,
),
drupal_get_path
(
'module'
,
'commerce_datatrans'
)
.
'/commerce_datatrans.js'
,
...
...
@@ -738,12 +750,8 @@ function commerce_datatrans_refund_request($transaction, $amount = NULL) {
$writer
->
endDocument
();
$xml
=
$writer
->
flush
();
if
(
strpos
(
$payment_method
[
'settings'
][
'up_start_url'
],
'pilot'
)
!==
FALSE
)
{
$url
=
'https://pilot.datatrans.biz/upp/jsp/XML_processor.jsp'
;
}
else
{
$url
=
'https://payment.datatrans.biz/upp/jsp/XML_processor.jsp'
;
}
$url
=
_commerce_datatrans_get_url
(
$payment_method
,
'SETTLEMENT'
);
$options
=
[
'headers'
=>
[
'Content-Type'
=>
'text/xml;charset=UTF-8'
,
...
...
@@ -754,3 +762,27 @@ function commerce_datatrans_refund_request($transaction, $amount = NULL) {
];
return
drupal_http_request
(
$url
,
$options
);
}
/**
* Returns the datatrans url for various actions.
*
* @param array $payment_method
* The payment method array. The only thing used is the test/prod switch
* $payment_method['settings']['environment'].
* @param string $type
* The url type. One of 'START', 'SCRIPT' or 'SETTLEMENT'. Case matters.
*
* @return The datatrans url to use or FALSE if $type is invalid.
*/
function
_commerce_datatrans_get_url
(
$payment_method
,
$type
=
'START'
)
{
if
(
!
empty
(
$payment_method
[
'settings'
][
'environment'
])
&&
$payment_method
[
'settings'
][
'environment'
]
==
'test'
)
{
$env
=
'TEST'
;
}
else
{
$env
=
'PROD'
;
}
if
(
defined
(
"COMMERCE_DATATRANS_
{
$type
}
_URL_
{
$env
}
"
))
{
return
constant
(
"COMMERCE_DATATRANS_
{
$type
}
_URL_
{
$env
}
"
);
}
return
FALSE
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment