Skip to content

Commit

Permalink
fix(action-network): handle donation transaction status update in API…
Browse files Browse the repository at this point in the history
… workflow
  • Loading branch information
sergiomario committed Jan 16, 2025
1 parent 1ed719f commit e31e23a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions action-network/web/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,25 @@ def donation(payload: Donation):
if payload.amount > 999999:
raise ValueError("Amount exceeds allowed limit.")

checkout_data = payload.checkout_data
address = checkout_data.address
phone = checkout_data.phone
checkout_data = payload.checkout_data or {}
address = checkout_data.get('address', {})
phone = checkout_data.get('phone', None)

item = {
'name': checkout_data.name.title(),
'email': checkout_data.email,
'name': checkout_data.get('name', '').title(),
'email': checkout_data.get('email', ''),
'metadata': {
'amount': f"{str(payload.amount)[:-2]}.00",
'transaction_status': payload.transaction_status,
'payment_method': payload.payment_method,
'recurring': payload.subscription,
'recurring_period': "Monthly" if payload.subscription else None
},
'address_line': f"{address.street_number} {address.street}, {address.complementary}".strip(', '),
'locality': address.city,
'region': address.state,
'postal_code': address.zipcode,
'phone': f"+55{phone.ddd}{phone.number}" if phone else None
'address_line': f"{address.get('street_number', '')} {address.get('street', '')}, {address.get('complementary', '')}".strip(', '),
'locality': address.get('city', ''),
'region': address.get('state', ''),
'postal_code': address.get('zipcode', ''),
'phone': f"+55{phone['ddd']}{phone['number']}" if phone else None
}

item['name'], item['given_name'], item['family_name'] = normalize_name(item['name'], None, None)
Expand Down Expand Up @@ -130,6 +130,7 @@ def to_payload(data: Payload):
response['action'] = 'form'

elif table == 'donations':
payload.checkout_data = payload.get('checkout_data', {})
response = donation(payload=payload)
response['action'] = 'donation'

Expand Down

0 comments on commit e31e23a

Please sign in to comment.