class SellPriceTest1(TestCase): def setUp(self): mock_http('GET https://coinbase.com/api/v1/prices/sell', self.response_body) def test_sell_price_without_auth(self): self.go(account_setup.without_auth()) def test_sell_price_with_key(self): self.go(account_setup.with_key()) def test_sell_price_with_oauth(self): self.go(account_setup.with_oauth()) def go(self, account): this(account.sell_price()).should.equal(self.expected_price) params = last_request_params() params.pop('api_key', None) this(params).should.equal({'qty': ['1']}) response_body = """ { "amount": "63.31", "currency": "USD" } """ expected_price = CoinbaseAmount('63.31', 'USD')
def main(): coinbase_operator = coinbase_api() orders = Orders.objects.filter(status='4', active=True).all() for order in orders: amount = Decimal(order.on_sales.amount_bitcoin) * int(order.total_ticket) print amount comission = amount/10 comission = comission + Decimal(0.0001) print comission amount = amount - comission # without comission print amount try: c_amount = CoinbaseAmount(amount, 'BTC') coinbase_operator.send_bitcoin(adress=order.user_url_for_btc_send, amount=c_amount, note='fazladanbilet sends your bitcoin') order.status = '0' order.save() template = get_template("mail_send_bitcoin.html") context = Context({'username': order.on_sales.member.username, 'ticket_name': order.on_sales.title, 'bitcoin_url': order.user_url_for_btc_send, 'amount': amount}) #send amount content = template.render(context) mailgun_operator = mailgun() mailgun_operator.send_mail_with_html(order.on_sales.member.email, content) except Exception as e: print e mailgun_operator = mailgun() text = str(order.id)+' '+str(order.on_sales.member.username)+' failure payment' mailgun_operator.send_mail('*****@*****.**', text)
def test_send_btc_to_email_address_with_oauth(self): account = account_setup.with_oauth() tx = account.send( to_address='*****@*****.**', amount=CoinbaseAmount('0.1', 'BTC'), ) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({}) this(tx).should.equal(expected_transaction)
def test_send_usd_to_bitcoin_address_with_oauth(self): account = account_setup.with_oauth() tx = account.send( to_address='7nregFERfhn8f34FERf8yn8fEGgfe274nv', amount=CoinbaseAmount('12', 'USD'), ) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({}) this(tx).should.equal(expected_transaction)
def test_send_btc_to_email_address_with_key(self): account = account_setup.with_key() tx = account.send( to_address='*****@*****.**', amount=CoinbaseAmount('12', 'USD'), ) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({ 'api_key': [account_setup.api_key], }) this(tx).should.equal(expected_transaction)
def test_send_btc_to_bitcoinaddress_with_key(self): account = account_setup.with_key() tx = account.send( to_address='7nregFERfhn8f34FERf8yn8fEGgfe274nv', amount=CoinbaseAmount('0.1', 'BTC'), idem='abc', ) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({ 'api_key': [account_setup.api_key], }) this(tx).should.equal(expected_transaction)
}, "total": { "amount": "13.84", "currency": "USD" }, "description": "Paid for with $13.84 from Test xxxxx3111." } } ], "total_count": 1, "num_pages": 1, "current_page": 1 } """ expected_transfer = CoinbaseTransfer( type='Buy', code='QPCUCZHR', created_at=datetime(2013, 2, 27, 23, 28, 18, tzinfo=tzoffset(None, -28800)), fees_coinbase=CoinbaseAmount('.14', 'USD'), fees_bank=CoinbaseAmount('.15', 'USD'), payout_date=datetime(2013, 3, 5, 18, 0, 0, tzinfo=tzoffset(None, -28800)), transaction_id='5011f33df8182b142400000e', status=CoinbaseTransfer.Status.pending, btc_amount=CoinbaseAmount('1', 'BTC'), subtotal_amount=CoinbaseAmount('13.55', 'USD'), total_amount=CoinbaseAmount('13.84', 'USD'), description='Paid for with $13.84 from Test xxxxx3111.', )
"request": false, "sender": { "email": "*****@*****.**", "id": "016bde60ac5603bde5300011", "name": "*****@*****.**" }, "status": "pending" } } """ expected_transaction = CoinbaseTransaction( id='69ab532bde59cfba595c5738', created_at=datetime(2013, 3, 31, 15, 2, 58, tzinfo=tzoffset(None, -25200)), notes='', amount=CoinbaseAmount('-0.1', 'BTC'), status=CoinbaseTransaction.Status.pending, request=False, sender=CoinbaseContact( id='016bde60ac5603bde5300011', email='*****@*****.**', name='*****@*****.**', ), recipient=CoinbaseContact( id='72370bd60efa506c6596d56e', email='*****@*****.**', name='Bob', ), recipient_address='*****@*****.**', recipient_type='coinbase', )
this(last_request_params()).should.equal({ 'api_key': [account_setup.api_key], }) this(transaction).should.equal(expected_transaction) def test_request_bitcoin_with_oauth(self): account = account_setup.with_oauth() transaction = account.request(**request_args) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({}) this(transaction).should.equal(expected_transaction) request_args = { 'from_email': '*****@*****.**', 'amount': CoinbaseAmount('1', 'BTC'), 'notes': 'Testing', } expected_request_json = { 'transaction': { 'from': '*****@*****.**', 'amount': '1', 'notes': 'Testing', } } response_body = """ { "success": true, "transaction": {
def test_creating_a_button_with_oauth(self): account = account_setup.with_oauth() button = account.create_button(button_spec) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({}) this(button).should.equal(expected_button) button_spec = CoinbasePaymentButton( name='abc def', description='ghi jkl', text='lol', custom='12345x', custom_secure=True, price=CoinbaseAmount('102.76', 'USD'), type='subscription', repeat='monthly', style='subscription_small', callback_url='https://example.com/callback', success_url='https://example.com/success', cancel_url='https://example.com/cancel', info_url='https://example.com/info', auto_redirect=True, suggested_prices=['5', '20.25', '250'], include_address=True, include_email=True, variable_price=True, ) expected_request_json = {
expected_orders = [ CoinbaseOrder( id='8DJ2Z9AQ', created_at=datetime(2014, 4, 21, 10, 25, 50, tzinfo=tzoffset(None, -25200)), status=CoinbaseOrder.Status.expired, receive_address='8uREGg34ji4gn43M93cuibhbkfi6FbyF1g', button=CoinbaseOrder.Button( id='0fde6d456181be1279fef6879d6897a3', description='warm and fuzzy', name='Alpaca socks', type='buy_now', ), custom='abcdef', total=CoinbaseAmount.BtcAndNative( btc=CoinbaseAmount('.01818000', 'BTC'), native=CoinbaseAmount('9', 'USD'), ), customer=CoinbaseOrder.Customer(), ), CoinbaseOrder( id='J3KAD35D', created_at=datetime(2014, 4, 21, 9, 56, 57, tzinfo=tzoffset(None, -25200)), status=CoinbaseOrder.Status.complete, receive_address='b87nihewshngyuFUbu6fy5vbtdtryfhhj1', button=CoinbaseOrder.Button( id='69adb65c95af59ed5b9ab5de55a579db', description='20% off', name='Pineapple', type='buy_now', ),
"request": false, "sender": { "email": "*****@*****.**", "id": "016bde60ac5603bde5300011", "name": "*****@*****.**" }, "status": "pending" } } """ expected_transaction = CoinbaseTransaction( id='69ab532bde59cfba595c5738', created_at=datetime(2013, 3, 31, 15, 2, 58, tzinfo=tzoffset(None, -25200)), notes='', amount=CoinbaseAmount('-12', 'USD'), status=CoinbaseTransaction.Status.pending, request=False, sender=CoinbaseContact( id='016bde60ac5603bde5300011', email='*****@*****.**', name='*****@*****.**', ), recipient=CoinbaseContact( id='72370bd60efa506c6596d56e', email='*****@*****.**', name='Bob', ), recipient_address='*****@*****.**', recipient_type='coinbase', )
"request": false, "sender": { "email": "*****@*****.**", "id": "4efec8d7bedd320001000003", "name": "Brian Armstrong" }, "status": "complete" } } ] } """ expected_transactions = [ CoinbaseTransaction( amount=CoinbaseAmount('1', 'BTC'), created_at=datetime(2013, 3, 23, 17, 43, 35, tzinfo=tzoffset(None, -25200)), id='514e4c37802e1bf69100000e', notes='Testing', recipient=CoinbaseContact( id='509e01ca12838e0200000212', email='*****@*****.**', name='*****@*****.**', ), recipient_type='coinbase',
def test_getting_user_details_with_oauth(self): account = account_setup.with_oauth() user = account.get_user_details() this(user.id).should.equal("509f01da12837e0201100212") this(user.balance).should.equal(CoinbaseAmount('1225.86084181', 'BTC'))
}) this(order).should.equal(expected_order) def test_create_order_from_button_with_oauth(self): account = account_setup.with_oauth() order = account.create_order_from_button( button_id='93865b9cae83706ae59220c013bc0afd') this(last_request_body()).should.equal(b'') this(last_request_params()).should.equal({}) this(order).should.equal(expected_order) button_spec = CoinbasePaymentButton( name='test', type='buy_now', price=CoinbaseAmount('1.23', 'USD'), ) expected_button_json = { 'button': { 'name': 'test', 'type': 'buy_now', 'price_string': '1.23', 'price_currency_iso': 'USD', } } response_body = """ { "success": true, "order": {
"hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", "confirmations": 0 }, "refund_address": "1HcmQZarSgNuGYz4r7ZkjYumiU4PujrNYk" } } """ expected_order = CoinbaseOrder( id='5RTQNACF', created_at=datetime(2012, 12, 9, 21, 23, 41, tzinfo=tzoffset(None, -28800)), status=CoinbaseOrder.Status.complete, total=CoinbaseAmount.BtcAndNative( btc=CoinbaseAmount('1', 'BTC'), native=CoinbaseAmount('12.53', 'USD'), ), custom='order1234', receive_address='1NhwPYPgoPwr5hynRAsto5ZgEcw1LzM3My', button=CoinbaseOrder.Button( type='buy_now', name='Alpaca Socks', description='The ultimate in lightweight footwear', id='5d37a3b61914d6d0ad15b5135d80c19f', ), transaction=CoinbaseOrder.Transaction( id='514f18b7a5ea3d630a00000f', hash='4a5e1e4baab89f3a32518a88c31bc87f' '618f76673e2cc77ab2127b7afdeda33b', confirmations=0, ),
this(last_request_params()).should.equal({ 'api_key': [account_setup.api_key], }) this(button).should.equal(expected_button) def test_creating_a_button_with_oauth(self): account = account_setup.with_oauth() button = account.create_button(button_spec) this(last_request_json()).should.equal(expected_request_json) this(last_request_params()).should.equal({}) this(button).should.equal(expected_button) button_spec = CoinbasePaymentButton( name='a', price=CoinbaseAmount('5', 'USD'), ) expected_request_json = { 'button': { 'name': 'a', 'price_string': '5', 'price_currency_iso': 'USD', } } response_body = """ { "button": {
"transaction": { "id": "513eb768f12a9cf27400000b", "hash": "4cc5eec20cd692f3cdb7fc264a0e1d78b9a7e3d7b862dec1e39cf7e37ababc14", "confirmations": 0 } } } """ expected_order = CoinbaseOrder( id='A7C52JQT', created_at=datetime(2013, 3, 11, 22, 4, 37, tzinfo=tzoffset(None, -25200)), status=CoinbaseOrder.Status.complete, total=CoinbaseAmount.BtcAndNative( btc=CoinbaseAmount('.1', 'BTC'), native=CoinbaseAmount('.1', 'BTC'), ), custom='custom123', receive_address='mgrmKftH5CeuFBU3THLWuTNKaZoCGJU5jQ', button=CoinbaseOrder.Button( type='buy_now', name='test', description='', id='eec6d08e9e215195a471eae432a49fc7', ), transaction=CoinbaseOrder.Transaction( id='513eb768f12a9cf27400000b', hash='4cc5eec20cd692f3cdb7fc264a0e1d78' 'b9a7e3d7b862dec1e39cf7e37ababc14', confirmations=0, ),