Esempio n. 1
0
 def __init__(self, api_uri="https://bitpay.com", insecure=False, pem=key_utils.generate_pem(), tokens={}):
   self.uri = api_uri
   self.verify = not(insecure)
   self.pem = pem
   self.client_id = key_utils.get_sin_from_pem(pem)
   self.tokens = tokens
   self.user_agent = 'bitpay-python'
Esempio n. 2
0
 def __init__(self, api_uri="https://bitpay.com", insecure=False, pem=key_utils.generate_pem(), tokens={}):
   self.uri = api_uri
   self.verify = not(insecure)
   self.pem = pem
   self.client_id = key_utils.get_sin_from_pem(pem)
   self.tokens = tokens
   self.user_agent = 'bitpay-python'
Esempio n. 3
0
def auth_start(request, **kwargs):
    if request.event.settings.payment_bitpay_token:
        messages.error(request, _('You are already connected to BitPay.'))
        return redirect(
            reverse('control:event.settings.payment.provider',
                    kwargs={
                        'organizer': request.event.organizer.slug,
                        'event': request.event.slug,
                        'provider': 'bitpay'
                    }))
    request.session['payment_bitpay_auth_event'] = request.event.pk
    pem = request.event.settings.payment_bitpay_pem
    if not pem:
        gs = GlobalSettingsObject()
        pem = gs.settings.payment_bitpay_pem = key_utils.generate_pem()

    sin = key_utils.get_sin_from_pem(pem)
    if request.GET.get('url'):
        url = request.GET.get('url')
    else:
        url = 'https://test.bitpay.com' if 'test' in request.GET else 'https://bitpay.com'
    try:
        r = requests.post(url + '/tokens',
                          json={
                              'label': settings.PRETIX_INSTANCE_NAME,
                              'facade': 'merchant',
                              'id': sin
                          })
    except requests.ConnectionError:
        messages.error(request,
                       _('Communication with BitPay was not successful.'))
    else:
        if r.status_code == 200:
            data = r.json()['data'][0]
            request.event.settings.payment_bitpay_token = data['token']
            request.event.settings.payment_bitpay_url = url
            return redirect(url + '/api-access-request?pairingCode=' +
                            data['pairingCode'])
        messages.error(request,
                       _('Communication with BitPay was not successful.'))

    return redirect(
        reverse('control:event.settings.payment.provider',
                kwargs={
                    'organizer': request.event.organizer.slug,
                    'event': request.event.slug,
                    'provider': 'bitpay'
                }))
Esempio n. 4
0
 def test_sin_from_pem(self):
   pem = '-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1f532dX+0O6QoAcGBSuBBAAK\noUQDQgAEjZcNa6Kdz6GQwXcUD9iJ+t1tJZCx7hpqBuJV2/IrQBfue8jh8H7Q/4vX\nfAArmNMaGotTpjdnymWlMfszzXJhlw==\n-----END EC PRIVATE KEY-----\n'
   assert utils.get_sin_from_pem(pem) == 'TeyN4LPrXiG5t2yuSamKqP3ynVk3F52iHrX'
Esempio n. 5
0
import bitpay.key_utils as key_utils

pem = key_utils.generate_pem()
with open("keys/local.pem", 'w') as f:
    f.write(pem)
sin = key_utils.get_sin_from_pem(pem)
print("Printing SIN")
print(sin)