perrich / sepawriter

Manage SEPA (Single Euro Payments Area) Credit and Debit Transfer for SEPA or international order.
Apache License 2.0
67 stars 48 forks source link

DebitTransfer #13

Closed alfredomar closed 7 years ago

alfredomar commented 7 years ago

Hi,

Can you put an example for debit transfer?? With mandatory, etc..

Thanks

perrich commented 7 years ago

Hi,

It's like a credit but you should add mandate extra data:

var sepaTransfer = new SepaDebitTransfer
{
    CreationDate = DateTime.Now,
    RequestedExecutionDate = date,
    InitiatingPartyName = StringUtils.RemoveInvalidChar(creditor.Name),
    Creditor = creditor,
    MessageIdentification = reference,
    PersonId = personid
};

foreach (var row in rows)
{
    var row_debtor = new SepaIbanData
    {
        Iban = row.iban,
        Bic = row.bic,
        Name = StringUtils.RemoveInvalidChar(row.name),
    };

    sepaTransfer.AddDebitTransfer(
        new SepaDebitTransferTransaction
        {
            Debtor = row_debtor,
            Amount = row.amount,
            RemittanceInformation = StringUtils.RemoveInvalidChar(row.comment),
            EndToEndId = StringUtils.RemoveInvalidChar(row.myId),
            DateOfSignature = row.dt_sign, // mandate sign date
            MandateIdentification = row.rum, // debtor unique mandate identifier
            SequenceType = row.is_first ? SepaSequenceType.FIRST : SepaSequenceType.RCUR,
        }
    );
}

sepaTransfer.Save(filename));

This API is used in production with a similar code.

You can find another sample in the unit tests sample ShouldValidateThePain00800103XmlSchema().