Created
June 4, 2018 17:15
-
-
Save nickhargreaves/78cdb64f234ab18aea4e06783963fa89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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