def app():
    print("Using the api...")
    print("Today: ", date.today().isoformat())

    doc = api.Document()
    ccti = api.CustomerCreditTransferInitiationV03()

    msgid = get_random_identifier("msg_snail")
    grphdr = api.GroupHeader32(
        MsgId=msgid,
        CreDtTm=datetime.utcnow().replace(microsecond=0).isoformat(),
        NbOfTxs="1")
    the_id_orgid_othr = api.GenericOrganisationIdentification1(Id="915109012")
    the_id_orgid_othr.set_SchmeNm(
        api.OrganisationIdentificationSchemeName1Choice(Cd="CUST"))
    the_id_orgid = api.OrganisationIdentification4()
    the_id_orgid.add_Othr(the_id_orgid_othr)
    the_id = api.Party6Choice(OrgId=the_id_orgid)
    initgpty = api.PartyIdentification32(Nm="Statsnail AS", Id=the_id)
    grphdr.set_InitgPty(initgpty)

    ccti.set_GrpHdr(grphdr)

    ccti.add_PmtInf(make_PmtInf())  # Add one payment

    doc.set_CstmrCdtTrfInitn(ccti)

    filetest = open("output.xml", 'w')
    doc.export(outfile=filetest, level=0)
    filetest.close()
def make_PmtInf():
    _PmtInf = api.PaymentInstructionInformation3(
        ReqdExctnDt=date.today().isoformat())
    _PmtInf.set_PmtInfId(get_random_identifier("pmt_snail"))  #Max35Text
    _PmtInf.set_PmtMtd("TRF")  #PaymentMethod3Code
    _PmtInf.set_NbOfTxs("1")  #Max15NumericText
    _PmtInf.set_CtrlSum(20)  #DecimalNumber
    _PmtInf.set_PmtTpInf(api.PaymentTypeInformation19(InstrPrty="NORM"))
    #pdb.set_trace()
    #PmtInf.set_ReqdExctnDt("1996-10-11") # Here be dragons
    #print(PmtInf.get_ReqdExctnDt())
    _PmtInf.set_Dbtr(
        api.PartyIdentification32(Nm="Statsnail AS",
                                  PstlAdr=api.PostalAddress6(Ctry="NO")))
    _PmtInf.set_DbtrAcct(
        api.CashAccount16(Id=api.AccountIdentification4Choice(
            Othr=api.GenericAccountIdentification1(
                Id="00001111000",
                SchmeNm=api.PersonIdentificationSchemeName1Choice(Cd="BANK"))),
                          Ccy="NOK"))
    _PmtInf.set_DbtrAgt(
        api.BranchAndFinancialInstitutionIdentification4(
            FinInstnId=api.FinancialInstitutionIdentification7(
                BIC="SPTRNO22XXX")))

    _PmtInf.add_CdtTrfTxInf(
        make_CdtTrfTxInf())  #CreditTransferTransactionInformation10

    return _PmtInf
def make_CdtTrfTxInf():
    _CdtTrfTxInf = api.CreditTransferTransactionInformation10()
    the_random_identifier = get_random_identifier("snail")
    _CdtTrfTxInf.set_PmtId(
        api.PaymentIdentification1(InstrId=the_random_identifier,
                                   EndToEndId=the_random_identifier))
    _CdtTrfTxInf.set_PmtTpInf(api.PaymentTypeInformation19(InstrPrty="NORM"))
    _CdtTrfTxInf.set_Amt(
        api.AmountType3Choice(InstdAmt=api.ActiveOrHistoricCurrencyAndAmount(
            Ccy="NOK", valueOf_="20")))
    _CdtTrfTxInf.set_Cdtr(
        api.PartyIdentification32(Nm="Joakim Xxx",
                                  PstlAdr=api.PostalAddress6(
                                      StrtNm="Epleveien Xx",
                                      PstCd="4635",
                                      TwnNm="Kristiansand",
                                      Ctry="NO")))
    _CdtTrfTxInf.set_CdtrAcct(
        api.CashAccount16(Id=api.AccountIdentification4Choice(
            Othr=api.GenericAccountIdentification1(
                Id="00001122222",
                SchmeNm=api.PersonIdentificationSchemeName1Choice(
                    Cd="BBAN")))))
    _RmtInf = api.RemittanceInformation5()
    _RmtInf.add_Ustrd("Unstructured Remittance Test Message Max 140")
    _CdtTrfTxInf.set_RmtInf(_RmtInf)
    return _CdtTrfTxInf
Esempio n. 4
0
def make_PmtInf(name, postal_addr, iban, currency, bank, payment_id,
                payment_date, payment_list):
    _PmtInf = api.PaymentInstructionInformation3(
        ReqdExctnDt=payment_date.isoformat())

    _PmtInf.set_PmtInfId(payment_id)  #Max35Text
    _PmtInf.set_PmtMtd("TRF")  #PaymentMethod3Code TRF = "Credit Transfer"
    _PmtInf.set_NbOfTxs(len(payment_list))  #Max15NumericText
    _PmtInf.set_CtrlSum(sum([int(x[4]) for x in payment_list]))  #DecimalNumber
    _PmtInf.set_PmtTpInf(api.PaymentTypeInformation19(
        InstrPrty="NORM"))  # NORM = Normal Priority
    _PmtInf.set_Dbtr(api.PartyIdentification32(Nm=name, PstlAdr=postal_addr))
    _PmtInf.set_DbtrAcct(
        api.CashAccount16(Id=api.AccountIdentification4Choice(IBAN=iban),
                          Ccy=currency))
    _PmtInf.set_DbtrAgt(
        api.BranchAndFinancialInstitutionIdentification4(
            FinInstnId=api.FinancialInstitutionIdentification7(BIC=bank)))

    for payment in payment_list:
        name = "{} {}".format(payment[1], payment[0])
        name = unidecode.unidecode(name)
        _PmtInf.add_CdtTrfTxInf(
            make_CdtTrfTxInf(payment_id="PAYMENT FOR {}".format(name),
                             amount=payment[4],
                             name=name,
                             iban=payment[2].replace(
                                 " ",
                                 "")))  #CreditTransferTransactionInformation10

    return _PmtInf
Esempio n. 5
0
def make_CdtTrfTxInf(payment_id, amount, name, iban):
    _CdtTrfTxInf = api.CreditTransferTransactionInformation10()
    _CdtTrfTxInf.set_PmtId(
        api.PaymentIdentification1(InstrId=payment_id, EndToEndId=payment_id))
    _CdtTrfTxInf.set_PmtTpInf(api.PaymentTypeInformation19(InstrPrty="NORM"))
    _CdtTrfTxInf.set_Amt(
        api.AmountType3Choice(InstdAmt=api.ActiveOrHistoricCurrencyAndAmount(
            Ccy="EUR", valueOf_=amount)))
    _CdtTrfTxInf.set_Cdtr(api.PartyIdentification32(Nm=name))
    _CdtTrfTxInf.set_CdtrAcct(
        api.CashAccount16(Id=api.AccountIdentification4Choice(IBAN=iban)))
    _RmtInf = api.RemittanceInformation5()
    _RmtInf.add_Ustrd(payment_id)
    _CdtTrfTxInf.set_RmtInf(_RmtInf)
    return _CdtTrfTxInf
Esempio n. 6
0
def app():
    utcdate = time.strftime('%Y%m%d', time.gmtime(time.time()))

    parser = argparse.ArgumentParser(
        description=
        'Generate SCT SEPA XML file containing a list of payment to do',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('name', help='payor name')
    parser.add_argument('bank', help='payor bank (BIC)')
    parser.add_argument('bank_account', help='payor bank account')
    parser.add_argument('IBAN', help='payor IBAN')
    parser.add_argument('csv',
                        type=argparse.FileType('r'),
                        help='the CSV file to read from')
    parser.add_argument('--output',
                        type=argparse.FileType('w'),
                        default="output.xml",
                        help='output file name')
    parser.add_argument('--currency',
                        default="EUR",
                        help='currency for the payments')
    parser.add_argument(
        '--message_id',
        default="PAYMENT GENERATED ON {}".format(utcdate),
        help=
        'message id used in the group header section (text length must be < 35 chars)'
    )
    parser.add_argument(
        '--payment_id',
        default="PAYMENT GENERATED ON {}".format(utcdate),
        help=
        'payment id used in the transfer section (text length must be < 35 chars)'
    )
    parser.add_argument('--payment_date',
                        type=date.fromisoformat,
                        default=date.today() + timedelta(days=7),
                        help='date of the payment (YYYY-MM-DD)')
    parser.add_argument('--debtor_bank_account',
                        type=date.fromisoformat,
                        default=date.today() + timedelta(days=7),
                        help='date of the payment (YYYY-MM-DD)')
    parser.add_argument('--street_name',
                        default=None,
                        help='payor street address')
    parser.add_argument('--post_code', default=None, help='payor post code')
    parser.add_argument('--town', default=None, help='payor town')
    parser.add_argument('--country',
                        default=None,
                        help='payor country (2 letters code)')

    args = parser.parse_args()

    payment_list = [x.split(',') for x in args.csv.readlines()]

    doc = api.Document()
    ccti = api.CustomerCreditTransferInitiationV03()
    grphdr = api.GroupHeader32(
        MsgId=args.message_id,
        CreDtTm=datetime.utcnow().replace(microsecond=0).isoformat(),
        NbOfTxs=len(payment_list),
        CtrlSum=sum([int(x[4]) for x in payment_list]))
    the_id_orgid_othr = api.GenericOrganisationIdentification1(
        Id=args.bank_account)
    the_id_orgid_othr.set_SchmeNm(
        api.OrganisationIdentificationSchemeName1Choice(Cd="BANK"))
    the_id_orgid = api.OrganisationIdentification4()
    the_id_orgid.add_Othr(the_id_orgid_othr)
    the_id = api.Party6Choice(OrgId=the_id_orgid)
    initgpty = api.PartyIdentification32(Nm=args.name, Id=the_id)
    grphdr.set_InitgPty(initgpty)

    ccti.set_GrpHdr(grphdr)

    postal_addr = api.PostalAddress6(StrtNm=args.street_name,
                                     PstCd=args.post_code,
                                     TwnNm=args.town,
                                     Ctry=args.country)
    ccti.add_PmtInf(
        make_PmtInf(args.name, postal_addr, args.IBAN, args.currency,
                    args.bank, args.payment_id, args.payment_date,
                    payment_list))

    doc.set_CstmrCdtTrfInitn(ccti)

    args.output.write('<?xml version="1.0" encoding="utf-8"?>\n')
    doc.export(outfile=args.output, level=0)
    args.output.close()