Files @ f3e8f774c793
Branch filter:

Location: NPO-Accounting/import2ledger/import2ledger/importers/stripe.py

Brett Smith
stripe: Extract more columns from payment data.
import decimal

from . import _csv
from .. import strparse

class PaymentImporter(_csv.CSVImporterBase):
    NEEDED_FIELDS = frozenset([
        'Converted Currency',
        'Created (UTC)',
        'Fee',
        'Status',
        'Tax',
    ])
    COPIED_FIELDS = {
        'Card Name': 'payee',
        'Converted Amount': 'amount',
        'Customer Email': 'customer_email',
        'Customer ID': 'customer_id',
        'Description': 'description',
        'Transfer': 'payout_id',
        'id': 'payment_id',
    }
    DATE_FMT = '%Y-%m-%d'

    def _read_row(self, row):
        if (row['Status'] != 'Paid') and (row['Status'] != 'Refunded'):
            return None
        else:
            date_s = strparse.slice_words(row['Created (UTC)'], 0, limit=1)
            return {
                'currency': row['Converted Currency'].upper(),
                'date': strparse.date(date_s, self.DATE_FMT),
                'fee': strparse.currency_decimal(row['Fee']),
                'tax': strparse.currency_decimal(row['Tax']),
            }