Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Integrasi SWIFT (Python) #1845

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Integrasi SWIFT (Python)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import requests

def send_swift_message(sender_bank, sender_account, receiver_bank, receiver_account, amount, currency):
swift_message = f"""
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02">
<FIToFICstmrCdtTrf>
<GrpHdr>
<MsgId>{sender_bank}-{receiver_bank}-001</MsgId>
<CreDtTm>2024-11-23T10:00:00</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<SttlmInf>
<SttlmMtd>CLRG</SttlmMtd>
</SttlmInf>
</GrpHdr>
<CdtTrfTxInf>
<PmtId>
<InstrId>{sender_account}-TX001</InstrId>
<EndToEndId>{receiver_account}-TX001</EndToEndId>
</PmtId>
<Amt>
<InstdAmt Ccy="{currency}">{amount}</InstdAmt>
</Amt>
<CdtrAgt>
<FinInstnId>
<BIC>{receiver_bank}</BIC>
</FinInstnId>
</CdtrAgt>
<Cdtr>
<Nm>{receiver_account}</Nm>
</Cdtr>
</CdtTrfTxInf>
</FIToFICstmrCdtTrf>
</Document>
"""
# Send the SWIFT message to the receiver bank's endpoint
response = requests.post(
url="https://api.swiftbank.com/send",
headers={"Content-Type": "application/xml"},
data=swift_message,
)
return response.status_code, response.text
Loading