This repository was archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpisp_example.py
84 lines (70 loc) · 4.33 KB
/
pisp_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import logging
import enablebanking
logging.getLogger().setLevel(logging.INFO)
REDIRECT_URL = "https://enablebanking.com" # PUT YOUR REDIRECT URI HERE
def alior_settings():
return {
"sandbox": True,
"clientId": "client-id", # API client ID
"clientSecret": "client-secret",
"certPath": "cert-path", # Path or URI QWAC certificate in PEM format
"keyPath": "key-path", # Path or URI to QWAC certificate private key in PEM format
"signKeyPath": "sign-key-path", # Path or URI to QSeal certificate in PEM format
"signPubKeySerial": "sign-pub-key-serial", # Public serial key of the QSeal certificate located in signKeyPath
"signFingerprint": "sign-fingerprint",
"signCertUrl": "sign-cert-url",
"accessToken": None,
"consentId": None,
"redirectUri": REDIRECT_URL,
"paymentAuthRedirectUri": REDIRECT_URL, # URI where clients are redirected to after payment authorization.
"paymentAuthState": "test" # This value returned to paymentAuthRedirectUri after payment authorization.
}
def read_redirected_url(url, redirect_url):
print("Please, open this page in browser: " + url)
print("Login, authenticate and copy paste back the URL where you got redirected.")
print(f"URL: (starts with %s): " % redirect_url)
redirected_url = input() # insert your url
return redirected_url
def main():
api_client = enablebanking.ApiClient("Alior", connector_settings=alior_settings()) # Create client instance.
pisp_api = enablebanking.PISPApi(api_client)
payment_request_resource = enablebanking.PaymentRequestResource(
payment_type_information=enablebanking.PaymentTypeInformation(service_level="SEPA", # will be resolved to "pis:EEA"
local_instrument="SEPA"), # set explicitly, can also be for example SWIFT or ELIXIR
credit_transfer_transaction=[
enablebanking.CreditTransferTransaction(
instructed_amount=enablebanking.AmountType(
amount="12.25",
currency="EUR"),
beneficiary=enablebanking.Beneficiary(
creditor=enablebanking.PartyIdentification(name="Creditor Name",
postal_address={"country": "RO",
"addressLine": ["Creditor Name",
"Creditor Address 1",
"Creditor Address 2"]}),
creditor_account=enablebanking.AccountIdentification(iban="RO56ALBP0RON421000045875"),
),
remittance_information=["Some remittance information"],
),
],
debtor=enablebanking.PartyIdentification(name="Debtor Name",
postal_address={"country": "PL",
"addressLine": ["Debtor Name",
"Debtor Address 1",
"Debtor Address 2"]}),
debtor_account=enablebanking.AccountIdentification(iban="PL63249000050000400030900682"),
)
request_creation = pisp_api.make_payment_request(payment_request_resource)
logging.info("Request creation: %s", request_creation)
redirected_url = read_redirected_url(request_creation.links.consent_approval.href, REDIRECT_URL) # calling helper functions for CLI interaction
auth_api = enablebanking.AuthApi(api_client) # Create authentication interface.
parsed_query_params = auth_api.parse_redirect_url(redirected_url)
logging.info("Query params: %s", parsed_query_params)
payment_request_confirmation = pisp_api.make_payment_request_confirmation(
request_creation.payment_request_resource_id,
confirmation=enablebanking.PaymentRequestConfirmation(
psu_authentication_factor=parsed_query_params.code
))
logging.info("Payment request confirmation: %s", payment_request_confirmation)
if __name__ == "__main__":
main()