Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commerce_datatrans
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
commerce_datatrans
Commits
be6b80cd
Commit
be6b80cd
authored
8 years ago
by
Primoz Hmeljak
Browse files
Options
Downloads
Patches
Plain Diff
by Primsi: add and cleanup heper method copied from payment_datatrans module.
parent
81667b0c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/DatatransHelper.php
+156
-0
156 additions, 0 deletions
src/DatatransHelper.php
with
156 additions
and
0 deletions
src/DatatransHelper.php
0 → 100644
+
156
−
0
View file @
be6b80cd
<?php
namespace
Drupal\commerce_datatrans
;
use
Drupal\Component\Utility\Crypt
;
use
Drupal\Core\Site\Settings
;
use
Drupal\payment\Entity\PaymentInterface
;
/**
* Helper methods for various Datatrans related tasks.
*/
class
DatatransHelper
{
/**
* Used for generation an internal key for validation purposes.
*
* @param PaymentInterface $payment
* Payment Interface.
*
* @return string
* The generated key.
*/
public
static
function
generateDatatransKey
(
PaymentInterface
$payment
)
{
return
Crypt
::
hashBase64
(
$payment
->
id
()
.
$payment
->
getPaymentStatus
()
->
getPluginId
()
.
Settings
::
getHashSalt
()
.
\Drupal
::
service
(
'private_key'
)
->
get
());
}
/**
* Generates the server side sign to compare with the datatrans post data.
*
* @param string $hmac_key
* The hmac key.
* @param string $merchant_id
* Unique Merchant Identifier (assigned by Datatrans).
* @param string $amount
* Transaction amount in cents or smallest available unit of the currency.
* @param string $currency
* Transaction currency – ISO Character Code (CHF, USD, EUR etc.).
* @param string|int $transaction_reference
* Our reference number.
*
* @return string
* The computed hash.
*/
public
static
function
generateSign
(
$hmac_key
,
$merchant_id
,
$amount
,
$currency
,
$transaction_reference
)
{
$hmac_data
=
$merchant_id
.
$amount
.
$currency
.
$transaction_reference
;
return
hash_hmac
(
'md5'
,
$hmac_data
,
pack
(
'H*'
,
$hmac_key
));
}
/**
* Datatrans error code mapping.
*
* @param int $code
* Provide error code from Datatrans callback.
*
* @return bool|FALSE|mixed|string
* Returns error message.
*/
public
static
function
mapErrorCode
(
$code
)
{
switch
(
$code
)
{
case
'1001'
:
$message
=
t
(
'Datrans transaction failed: missing required parameter.'
);
break
;
case
'1002'
:
$message
=
t
(
'Datrans transaction failed: invalid parameter format.'
);
break
;
case
'1003'
:
$message
=
t
(
'Datatrans transaction failed: value of parameter not found.'
);
break
;
case
'1004'
:
case
'1400'
:
$message
=
t
(
'Datatrans transaction failed: invalid card number.'
);
break
;
case
'1007'
:
$message
=
t
(
'Datatrans transaction failed: access denied by sign control/parameter sign invalid.'
);
break
;
case
'1008'
:
$message
=
t
(
'Datatrans transaction failed: merchant disabled by Datatrans.'
);
break
;
case
'1401'
:
$message
=
t
(
'Datatrans transaction failed: invalid expiration date.'
);
break
;
case
'1402'
:
case
'1404'
:
$message
=
t
(
'Datatrans transaction failed: card expired or blocked.'
);
break
;
case
'1403'
:
$message
=
t
(
'Datatrans transaction failed: transaction declined by card issuer.'
);
break
;
case
'1405'
:
$message
=
t
(
'Datatrans transaction failed: amount exceeded.'
);
break
;
case
'3000'
:
case
'3001'
:
case
'3002'
:
case
'3003'
:
case
'3004'
:
case
'3005'
:
case
'3006'
:
case
'3011'
:
case
'3012'
:
case
'3013'
:
case
'3014'
:
case
'3015'
:
case
'3016'
:
$message
=
t
(
'Datatrans transaction failed: denied by fraud management.'
);
break
;
case
'3031'
:
$message
=
t
(
'Datatrans transaction failed: declined due to response code 02.'
);
break
;
case
'3041'
:
$message
=
t
(
'Datatrans transaction failed: Declined due to post error/post URL check failed.'
);
break
;
case
'10412'
:
$message
=
t
(
'Datatrans transaction failed: PayPal duplicate error.'
);
break
;
case
'-885'
:
case
'-886'
:
$message
=
t
(
'Datatrans transaction failed: CC-alias update/insert error.'
);
break
;
case
'-887'
:
$message
=
t
(
'Datatrans transaction failed: CC-alias does not match with cardno.'
);
break
;
case
'-888'
:
$message
=
t
(
'Datatrans transaction failed: CC-alias not found.'
);
break
;
case
'-900'
:
$message
=
t
(
'Datatrans transaction failed: CC-alias service not enabled.'
);
break
;
default
:
$message
=
t
(
'Datatrans transaction failed: undefined error.'
);
break
;
}
return
$message
;
}
}
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