Skip to content

Instantly share code, notes, and snippets.

@nickhargreaves
Created June 4, 2018 17:15
Show Gist options
  • Save nickhargreaves/78cdb64f234ab18aea4e06783963fa89 to your computer and use it in GitHub Desktop.
Save nickhargreaves/78cdb64f234ab18aea4e06783963fa89 to your computer and use it in GitHub Desktop.
@receiver(post_save, sender=Payment)
def call_payment_api(sender, instance, created, **kwargs):
if created:
# Initiate a Beyonic Collection Request to request money from the user
import beyonic
beyonic.api_key = settings.BEYONIC_API_KEY
response = beyonic.CollectionRequest.create(
phonenumber=instance.phone_number,
amount=instance.item.price,
currency=instance.item.currency,
description='Payment for ' + instance.item.model,
callback_url=reverse('merchant_payment'),
send_instructions=True
)
instance.request_response = str(response)
instance.remote_id = response['id']
instance.status = Payment.REQUEST_SENT
instance.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment