Ejemplo n.º 1
0
def verification(request):
    _user_id_external = request.user.id_external

    _sumsub_access_token_payload = {
        'userId': _user_id_external,
        'key': env('SUMSUB_KEY'),
    }

    try:
        _sumsub_request = requests.post('/'.join(
            [env('SUMSUB_HOST'), 'resources/accessTokens']),
                                        params=_sumsub_access_token_payload)

        _sumsub_request.raise_for_status()

        _sumsub_response = _sumsub_request.json()

        return render(
            request, 'launchpad/verification.html', {
                'sumsub': {
                    'host': env('SUMSUB_HOST'),
                    'token': _sumsub_response['token'],
                }
            })

    except RequestException:
        return render(request, 'launchpad/verification_unavailable.html')
Ejemplo n.º 2
0
#!/usr/bin/env python
import os
import sys
from project.settings import env

if __name__ == "__main__":
    os.environ.setdefault(env("DJANGO_SETTINGS_MODULE"), "project.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise


    current_path = os.path.dirname(os.path.abspath(__file__))
    sys.path.append(os.path.join(current_path, 'src'))

    execute_from_command_line(sys.argv)
Ejemplo n.º 3
0
def update(request):
    if request.method == 'POST':
        _param_errors = []
        _send_success_email = False
        _send_cancel_email = False

        if 'merchant' not in request.POST or request.POST.get('merchant') != env('COINPAYMENTS_MERCHANT_ID'):
            _param_errors.append('merchant')

        if not _param_errors:
            if request.POST.get('ipn_type') == 'api':
                _txn_id = request.POST.get('txn_id')
                _status = int(request.POST.get('status'))
                _status_text = request.POST.get('status_text')
                _email = request.POST.get('email')

                try:
                    with transaction.atomic():
                        _order = TokenOrders.objects.order_from_txn(txn_id=_txn_id).get()
                        _order.payment_status = _status
                        _order.payment_status_text = _status_text

                        if _status >= 1:
                            if not _order.tokens_credited:
                                _transaction = TokenTransactions(
                                    token_transaction_external_id=token_urlsafe(32),
                                    customer_external_id=_order.customer_external_id,
                                    transaction_type='Deposit',
                                    token_value=_order.token_value,
                                )

                                _transaction.save()
                                _send_success_email = True

                            _order.payment_received = True
                            _order.tokens_credited = True

                        elif _status == -1:
                            _send_cancel_email = True

                        _order.save()

                        if _send_success_email:
                            _message = AnymailMessage(
                                to=[_email],
                                tags=['Orders']
                            )
                            _message.template_id = 'a33525c2-8c99-4f8e-b7cd-b943e874c318'
                            _message.merge_global_data = {
                                'token_value': ' '.join([str("{:,.2f}".format(float(_order.token_value))), 'XTV']),
                            }
                            _message.metadata = {'payment-address': _order.payment_address}
                            _message.track_clicks = True

                            _message.send()

                        elif _send_cancel_email:
                            _message = AnymailMessage(
                                to=[_email],
                                tags=['Orders']
                            )
                            _message.template_id = 'f39a80c3-a381-4a15-822b-32fb08debbe4'
                            _message.merge_global_data = {
                                'token_value': ' '.join([str("{:,.2f}".format(float(_order.token_value))), 'XTV']),
                                'payment_currency_value': ' '.join([str(_order.payment_currency_value), _order.payment_currency]),
                                'payment_address': _order.payment_address,
                            }
                            _message.metadata = {'payment-address': _order.payment_address}
                            _message.track_clicks = True

                            _message.send()

                        return standard_response()

                except IntegrityError:
                    # TODO: Notify us of error
                    return standard_response()

        else:
            return HttpResponse('Missing required parameters: %s' % ', '.join(_param_errors), status=400)
    else:
        return HttpResponse('Method Not Allowed', status=405)
Ejemplo n.º 4
0
"""
django:
    https://docs.djangoproject.com/en/3.0/ref/settings/#secret-key
"""

from project.settings import env

SECRET_KEY = env("HCAP__SECRET_KEY", default="changeme")
Ejemplo n.º 5
0
#!/usr/bin/env python
import os
import sys
from project.settings import env

if __name__ == "__main__":
    os.environ.setdefault(env("DJANGO_SETTINGS_MODULE"), "project.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?")
        raise

    current_path = os.path.dirname(os.path.abspath(__file__))
    sys.path.append(os.path.join(current_path, 'src'))

    execute_from_command_line(sys.argv)
Ejemplo n.º 6
0
def buy(request):
    _user_id_external = request.user.id_external
    _user_email = request.user.email
    _user_eligibility_latest = UserEligibilityRegistry.objects.last_consent(
        external_id=_user_id_external)
    _token_cost_usd = 0.1

    if len(_user_eligibility_latest) == 0:
        return redirect('launchpad:eligibility')

    if request.method == 'POST':
        _buy_form = BuyForm(request.POST)

        if _buy_form.is_valid():
            _usd_value = _buy_form.cleaned_data.get('usd_value')
            _payment_currency = _buy_form.cleaned_data.get('payment_currency')

            _token_value = int(_usd_value) / _token_cost_usd
            _token_order_external_id = token_urlsafe(32)

            _cp_client = CryptoPayments(
                env('COINPAYMENTS_API_KEY'),
                env('COINPAYMENTS_API_SECRET'),
                env('COINPAYMENTS_IPN_URL'),
            )

            _token_order = TokenOrders(
                token_order_external_id=_token_order_external_id,
                customer_external_id=_user_id_external,
                usd_value=_usd_value,
                token_value=_token_value,
                payment_currency=_payment_currency,
            )

            _token_order.save()
            _token_order_id = _token_order.token_order_id

            _item_name = 'Centive Tokens (XTV)'
            _item_number = str(random.randint(
                10, 100)) + str(_token_order_id) + str(random.randint(10, 100))

            _cp_transaction = _cp_client.createTransaction({
                'amount':
                _usd_value,
                'currency1':
                'USD',
                'currency2':
                _payment_currency,
                'buyer_email':
                _user_email,
                'item_name':
                _item_name,
                'item_number':
                _item_number,
            })

            _token_order.payment_currency_value = _cp_transaction.amount
            _token_order.payment_address = _cp_transaction.address
            _token_order.txn_id = _cp_transaction.txn_id
            _token_order.confirms_needed = _cp_transaction.confirms_needed
            _token_order.timeout = _cp_transaction.timeout
            _token_order.status_url = _cp_transaction.status_url
            _token_order.qrcode_url = _cp_transaction.qrcode_url

            _token_order.save()

            _message = AnymailMessage(to=[_user_email], tags=['Orders'])
            _message.template_id = '9125877d-e602-4375-8ad2-74dbad9ec04d'
            _message.merge_global_data = {
                'token_value':
                ' '.join([str("{:,.2f}".format(float(_token_value))), 'XTV']),
                'confirms_needed':
                _cp_transaction.confirms_needed,
                'payment_currency_value':
                ' '.join([str(_cp_transaction.amount), _payment_currency]),
                'payment_address':
                _cp_transaction.address,
                'status_url':
                _cp_transaction.status_url,
            }
            _message.metadata = {'payment-address': _cp_transaction.address}
            _message.track_clicks = True

            _message.send()

            return redirect('launchpad:payment',
                            order_id=_token_order_external_id)

        else:
            return render(request, 'launchpad/buy.html',
                          {'buy_form': _buy_form})

    else:
        _buy_form = BuyForm()
        return render(request, 'launchpad/buy.html', {'buy_form': _buy_form})