Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
37a63546
Commit
37a63546
authored
Dec 24, 2020
by
Cédric Le Ninivin
Committed by
Rafael Monnerat
Dec 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_payzen: Start Moving SlapOS Payzen to REST API
parent
eb35deda
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
100 deletions
+92
-100
master/bt5/slapos_payzen/SkinTemplateItem/portal_skins/slapos_payzen/PaymentTransaction_updateStatus.py
...al_skins/slapos_payzen/PaymentTransaction_updateStatus.py
+7
-7
master/bt5/slapos_payzen/SkinTemplateItem/portal_skins/slapos_payzen/PayzenEvent_processUpdate.py
...m/portal_skins/slapos_payzen/PayzenEvent_processUpdate.py
+79
-88
master/bt5/slapos_payzen/SkinTemplateItem/portal_skins/slapos_payzen/PayzenEvent_processUpdate.xml
.../portal_skins/slapos_payzen/PayzenEvent_processUpdate.xml
+1
-1
master/bt5/slapos_payzen/WorkflowTemplateItem/portal_workflow/payzen_interface_workflow/scripts/PayzenEvent_generateNavigationPage.py
...ce_workflow/scripts/PayzenEvent_generateNavigationPage.py
+1
-0
master/bt5/slapos_payzen/WorkflowTemplateItem/portal_workflow/payzen_interface_workflow/scripts/PayzenEvent_updateStatus.py
...en_interface_workflow/scripts/PayzenEvent_updateStatus.py
+4
-4
No files found.
master/bt5/slapos_payzen/SkinTemplateItem/portal_skins/slapos_payzen/PaymentTransaction_updateStatus.py
View file @
37a63546
from
DateTime
import
DateTime
from
DateTime
import
DateTime
state
=
context
.
getSimulationState
()
state
=
context
.
getSimulationState
()
if
(
state
!=
'started'
)
or
(
context
.
getPaymentMode
()
!=
'payzen'
):
#
if (state != 'started') or (context.getPaymentMode() != 'payzen'):
return
#
return
else
:
#
else:
_
,
transaction_id
=
context
.
PaymentTransaction_getPayzenId
()
_
,
transaction_id
=
context
.
PaymentTransaction_getPayzenId
()
if
transaction_id
is
not
None
:
if
transaction_id
is
not
None
:
# so the payment is registered in payzen
# so the payment is registered in payzen
context
.
PaymentTransaction_createPayzenEvent
().
updateStatus
()
context
.
PaymentTransaction_createPayzenEvent
().
updateStatus
()
master/bt5/slapos_payzen/SkinTemplateItem/portal_skins/slapos_payzen/PayzenEvent_processUpdate.py
View file @
37a63546
...
@@ -13,104 +13,95 @@ transaction = payzen_event.getDestinationValue()
...
@@ -13,104 +13,95 @@ transaction = payzen_event.getDestinationValue()
if
transaction
is
None
:
if
transaction
is
None
:
raise
ValueError
(
"Unable to find related transaction"
)
raise
ValueError
(
"Unable to find related transaction"
)
assert
signature
in
(
True
,
False
)
isTransitionPossible
=
context
.
getPortalObject
().
portal_workflow
.
isTransitionPossible
if
signature
is
False
:
# signature is wrong, bye bye
status
=
data_kw
[
'status'
]
payzen_event
.
confirm
(
comment
=
'Signature does not match'
)
answer
=
data_kw
[
'answer'
]
if
status
!=
"SUCCESS"
:
error_code
=
answer
[
"error_code"
]
if
error_code
==
"PSP_010"
:
# Transaction Not Found
transaction_date
,
_
=
transaction
.
PaymentTransaction_getPayzenId
()
# Mark on payment transaction history log that transaction was not processed yet
payzen_event
.
confirm
()
payzen_event
.
acknowledge
(
comment
=
'Transaction not found on payzen side.'
)
#if int(DateTime()) - int(transaction_date) > 86400:
# if isTransitionPossible(transaction, 'cancel'):
# pass
# transaction.cancel(comment='Aborting unknown payzen payment.')
#else:
# Comment the last part until all transaction are using the new REST Api and order_id
storeWorkflowComment
(
transaction
,
'Error code PSP_010 (Not found) did not changed the document state.'
)
return
else
:
# Unknown errorCode
payzen_event
.
confirm
(
comment
=
'Unknown errorCode %r'
%
error_code
)
return
transaction_list
=
answer
[
"transactions"
]
if
len
(
transaction_list
)
!=
1
:
# Unexpected Number of Transactions
payzen_event
.
confirm
(
comment
=
'Unexpected Number of Transaction for this order'
)
return
return
isTransitionPossible
=
context
.
getPortalObject
().
portal_workflow
.
isTransitionPossible
transaction_kw
=
transaction_list
[
0
]
# See Full Status list at https://payzen.io/en-EN/rest/V4.0/api/kb/status_reference.html
mark_transaction_id_list
=
[
'AUTHORISED_TO_VALIDATE'
,
'WAITING_AUTHORISATION'
,
'WAITING_AUTHORISATION_TO_VALIDATE'
,
]
continue_transaction_id_list
=
[
'AUTHORISED'
,
'CAPTURED'
,
'PARTIALLY_AUTHORISED'
]
cancel_transaction_id_list
=
[
'REFUSED'
]
transaction_status
=
transaction_kw
[
'detailedStatus'
]
error_code
=
data_kw
[
'errorCode'
]
if
transaction_status
in
mark_transaction_id_list
:
if
error_code
==
'2'
:
transaction_date
,
_
=
transaction
.
PaymentTransaction_getPayzenId
()
# Mark on payment transaction history log that transaction was not processed yet
# Mark on payment transaction history log that transaction was not processed yet
storeWorkflowComment
(
transaction
,
'Transaction status %s did not changed the document state'
%
(
transaction_status
))
payzen_event
.
confirm
()
payzen_event
.
confirm
()
payzen_event
.
acknowledge
(
comment
=
'Transaction not found on payzen side.'
)
payzen_event
.
acknowledge
(
comment
=
'Automatic acknowledge as result of correct communication'
)
if
int
(
DateTime
())
-
int
(
transaction_date
)
>
86400
:
if
isTransitionPossible
(
transaction
,
'confirm'
):
if
isTransitionPossible
(
transaction
,
'cancel'
):
transaction
.
confirm
(
comment
=
'Confirmed as really saw in PayZen.'
)
transaction
.
cancel
(
comment
=
'Aborting unknown payzen payment.'
)
else
:
elif
transaction_status
in
continue_transaction_id_list
:
storeWorkflowComment
(
transaction
,
# Check authAmount and authDevise and if match, stop transaction
'Error code 2 (Not found) did not changed the document state.'
)
auth_amount
=
int
(
transaction_kw
[
'transactionDetails'
][
'cardDetails'
][
'authorizationResponse'
][
'amount'
])
return
auth_devise
=
transaction_kw
[
'transactionDetails'
][
'cardDetails'
][
'authorizationResponse'
][
'currency'
]
transaction_amount
=
int
((
round
(
transaction
.
PaymentTransaction_getTotalPayablePrice
(),
2
)
*
-
100
))
if
transaction_amount
!=
auth_amount
:
payzen_event
.
confirm
(
comment
=
'Received amount (%r) does not match stored on transaction (%r)'
%
(
auth_amount
,
transaction_amount
))
return
elif
error_code
==
'0'
:
transaction_devise
=
transaction
.
getResourceReference
()
transaction_code_mapping
=
{
if
transaction_devise
!=
auth_devise
:
'0'
:
'Initial (being treated)'
,
payzen_event
.
confirm
(
comment
=
'Received devise (%r) does not match stored on transaction (%r)'
%
(
auth_devise
,
transaction_devise
))
'1'
:
'To be validated '
,
'2'
:
'To be forced - Contact issuer'
,
'3'
:
'To be validated and authorized'
,
'4'
:
'Waiting for submission'
,
'5'
:
'Waiting for authorization'
,
'6'
:
'Submitted'
,
'7'
:
'Expired'
,
'8'
:
'Refused'
,
'9'
:
'Cancelled'
,
'10'
:
'Waiting'
,
'11'
:
'Being submitted'
,
'12'
:
'Being authorized'
,
'13'
:
'Failed'
,
}
mark_transaction_id_list
=
[
'0'
,
'1'
,
'3'
,
'5'
,
'10'
,
'11'
,
'12'
]
continue_transaction_id_list
=
[
'4'
,
'6'
]
cancel_transaction_id_list
=
[
'8'
]
transaction_status
=
data_kw
[
'transactionStatus'
]
transaction_status_description
=
transaction_code_mapping
.
get
(
transaction_status
,
None
)
if
transaction_status_description
is
None
:
payzen_event
.
confirm
(
comment
=
'Unknown transactionStatus %r'
%
transaction_status
)
return
return
if
transaction_status
in
mark_transaction_id_list
:
comment
=
'PayZen considered as paid.'
# Mark on payment transaction history log that transaction was not processed yet
if
isTransitionPossible
(
transaction
,
'confirm'
):
storeWorkflowComment
(
transaction
,
'Transaction status %s (%s) did not changed the document state'
%
(
transaction_status
,
transaction_status_description
))
transaction
.
confirm
(
comment
=
comment
)
if
isTransitionPossible
(
transaction
,
'start'
):
transaction
.
start
(
comment
=
comment
)
if
isTransitionPossible
(
transaction
,
'stop'
):
transaction
.
stop
(
comment
=
comment
)
if
transaction
.
getSimulationState
()
==
'stopped'
:
payzen_event
.
confirm
()
payzen_event
.
confirm
()
payzen_event
.
acknowledge
(
comment
=
'Automatic acknowledge as result of correct communication'
)
payzen_event
.
acknowledge
(
comment
=
'Automatic acknowledge as result of correct communication'
)
if
isTransitionPossible
(
transaction
,
'confirm'
):
transaction
.
confirm
(
comment
=
'Confirmed as really saw in PayZen.'
)
elif
transaction_status
in
continue_transaction_id_list
:
# Check authAmount and authDevise and if match, stop transaction
auth_amount
=
int
(
data_kw
[
'authAmount'
])
auth_devise
=
data_kw
[
'authDevise'
]
transaction_amount
=
int
((
round
(
transaction
.
PaymentTransaction_getTotalPayablePrice
(),
2
)
*
-
100
))
if
transaction_amount
!=
auth_amount
:
payzen_event
.
confirm
(
comment
=
'Received amount (%r) does not match stored on transaction (%r)'
%
(
auth_amount
,
transaction_amount
))
return
transaction_devise
=
transaction
.
getResourceValue
().
Currency_getIntegrationMapping
()
if
transaction_devise
!=
auth_devise
:
payzen_event
.
confirm
(
comment
=
'Received devise (%r) does not match stored on transaction (%r)'
%
(
auth_devise
,
transaction_devise
))
return
comment
=
'PayZen considered as paid.'
if
isTransitionPossible
(
transaction
,
'confirm'
):
transaction
.
confirm
(
comment
=
comment
)
if
isTransitionPossible
(
transaction
,
'start'
):
transaction
.
start
(
comment
=
comment
)
if
isTransitionPossible
(
transaction
,
'stop'
):
transaction
.
stop
(
comment
=
comment
)
if
transaction
.
getSimulationState
()
==
'stopped'
:
payzen_event
.
confirm
()
payzen_event
.
acknowledge
(
comment
=
'Automatic acknowledge as result of correct communication'
)
else
:
payzen_event
.
confirm
(
comment
=
'Expected to put transaction in stopped state, but achieved only %s state'
%
transaction
.
getSimulationState
())
elif
transaction_status
in
cancel_transaction_id_list
:
payzen_event
.
confirm
()
payzen_event
.
acknowledge
(
comment
=
'Refused payzen payment.'
)
if
isTransitionPossible
(
transaction
,
'cancel'
):
transaction
.
cancel
(
comment
=
'Aborting refused payzen payment.'
)
return
else
:
else
:
payzen_event
.
confirm
(
comment
=
'Transaction status %r (%r) is not supported'
\
payzen_event
.
confirm
(
comment
=
'Expected to put transaction in stopped state, but achieved only %s state'
%
transaction
.
getSimulationState
())
%
(
transaction_status
,
transaction_status_description
))
return
elif
transaction_status
in
cancel_transaction_id_list
:
payzen_event
.
confirm
()
payzen_event
.
acknowledge
(
comment
=
'Refused payzen payment.'
)
if
isTransitionPossible
(
transaction
,
'cancel'
):
transaction
.
cancel
(
comment
=
'Aborting refused payzen payment.'
)
return
else
:
else
:
# Unknown errorCode
payzen_event
.
confirm
(
comment
=
'Transaction status %r is not supported'
\
payzen_event
.
confirm
(
comment
=
'Unknown errorCode %r'
%
error_code
)
%
(
transaction_status
))
return
master/bt5/slapos_payzen/SkinTemplateItem/portal_skins/slapos_payzen/PayzenEvent_processUpdate.xml
View file @
37a63546
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
_params
</string>
</key>
<key>
<string>
_params
</string>
</key>
<value>
<string>
data_kw,
signature,
REQUEST=None
</string>
</value>
<value>
<string>
data_kw, REQUEST=None
</string>
</value>
</item>
</item>
<item>
<item>
<key>
<string>
id
</string>
</key>
<key>
<string>
id
</string>
</key>
...
...
master/bt5/slapos_payzen/WorkflowTemplateItem/portal_workflow/payzen_interface_workflow/scripts/PayzenEvent_generateNavigationPage.py
View file @
37a63546
...
@@ -29,6 +29,7 @@ payzen_dict = {
...
@@ -29,6 +29,7 @@ payzen_dict = {
'vads_amount'
:
str
(
int
(
round
((
payment_transaction
.
PaymentTransaction_getTotalPayablePrice
()
*
-
100
),
0
))),
'vads_amount'
:
str
(
int
(
round
((
payment_transaction
.
PaymentTransaction_getTotalPayablePrice
()
*
-
100
),
0
))),
'vads_trans_date'
:
now
.
toZone
(
'UTC'
).
asdatetime
().
strftime
(
'%Y%m%d%H%M%S'
),
'vads_trans_date'
:
now
.
toZone
(
'UTC'
).
asdatetime
().
strftime
(
'%Y%m%d%H%M%S'
),
'vads_trans_id'
:
transaction_id
,
'vads_trans_id'
:
transaction_id
,
'vads_order_id'
:
transaction_id
,
'vads_language'
:
'en'
,
'vads_language'
:
'en'
,
'vads_url_cancel'
:
vads_url_cancel
,
'vads_url_cancel'
:
vads_url_cancel
,
'vads_url_error'
:
vads_url_error
,
'vads_url_error'
:
vads_url_error
,
...
...
master/bt5/slapos_payzen/WorkflowTemplateItem/portal_workflow/payzen_interface_workflow/scripts/PayzenEvent_updateStatus.py
View file @
37a63546
...
@@ -6,20 +6,20 @@ if transaction_id is None:
...
@@ -6,20 +6,20 @@ if transaction_id is None:
raise
ValueError
(
'Transaction not registered in payzen integration tool'
)
raise
ValueError
(
'Transaction not registered in payzen integration tool'
)
payment_service
=
payzen_event
.
getSourceValue
(
portal_type
=
"Payzen Service"
)
payment_service
=
payzen_event
.
getSourceValue
(
portal_type
=
"Payzen Service"
)
data_kw
,
s
ignature
,
sent_text
,
received_text
=
payment_service
.
soap
_getInfo
(
data_kw
,
s
ent_text
,
received_text
=
payment_service
.
rest
_getInfo
(
transaction_date
.
toZone
(
'UTC'
).
asdatetime
(),
transaction_date
.
toZone
(
'UTC'
).
asdatetime
(),
transaction_id
)
transaction_id
)
# SENT
# SENT
sent
=
payzen_event
.
newContent
(
sent
=
payzen_event
.
newContent
(
title
=
'Sent
SOAP
'
,
title
=
'Sent
Data
'
,
portal_type
=
'Payzen Event Message'
,
portal_type
=
'Payzen Event Message'
,
text_content
=
sent_text
)
text_content
=
sent_text
)
# RECEIVED
# RECEIVED
payzen_event
.
newContent
(
payzen_event
.
newContent
(
title
=
'Received
SOAP
'
,
title
=
'Received
Data
'
,
portal_type
=
'Payzen Event Message'
,
portal_type
=
'Payzen Event Message'
,
text_content
=
received_text
,
text_content
=
received_text
,
predecessor_value
=
sent
)
predecessor_value
=
sent
)
payzen_event
.
PayzenEvent_processUpdate
(
data_kw
,
signature
)
payzen_event
.
PayzenEvent_processUpdate
(
data_kw
)
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