def test_transaction_caputre_later(self): transaction = Transaction( api_key='apikey', amount=314, card_hash='cardhash', capture=False, ) transaction.charge() transaction.capture()
def test_charge_fail(self): transaction = Transaction(api_key='apikey', amount=314, card_hash='foobar', payment_method='credit_card', installments=1, postback_url='https://post.back.url') with self.assertRaises(PagarmeApiError): transaction.charge()
def test_transaction_capture_later(self): transaction = Transaction( api_key='apikey', amount=314, card_hash='cardhash', capture=False, ) transaction.charge() transaction.capture()
def test_charge(self): transaction = Transaction(api_key='apikey', amount=314, card_hash='foobar', payment_method='credit_card', installments=1, postback_url='https://post.back.url') transaction.charge() self.assertEqual('processing', transaction.status)
def test_charge_transaction_with_valid_split_rules(self): transaction = Transaction( apikey='apikey', amount=10000, payment_method='boleto', split_rules = [ { "recipient_id":"idrecipient", "liable":"true", "charge_processing_fee":"true", "percentage":"20" }, { "recipient_id":"idrecipient2", "liable":"true", "charge_processing_fee":"true", "percentage":"80" } ] ) transaction.charge() self.assertEqual('processing',transaction.status)
def test_charge_transaction_with_invalid_split_rules_fails(self): transaction = Transaction( apikey='apikey', amount=10000, payment_method='boleto', split_rules = [ { "recipient_id":"idrecipient", "liable":"true", "charge_processing_fee":"true", "percentage":"80" }, { "recipient_id":"idrecipient", "liable":"true", "charge_processing_fee":"true", "percentage":"30" } ] ) with self.assertRaises(PagarmeApiError): transaction.charge()
def test_charge_fail(self): transaction = Transaction(api_key='apikey', amount=314, card_hash='foobar', payment_method='credit_card', installments=1, postback_url='https://post.back.url') with self.assertRaises(PagarmeApiError): transaction.charge()
def test_charge(self): transaction = Transaction(api_key='apikey', amount=314, card_hash='foobar', payment_method='credit_card', installments=1, postback_url='https://post.back.url') transaction.charge() self.assertEqual('processing', transaction.status)
def test_charge_with_card_hash(self): response = '''{ "date_updated":"2014-12-22T14:57:59.000Z", "ip":"187.112.12.183", "boleto_barcode":null, "cost":0, "refuse_reason":null, "id":173525, "card_holder_name":"Jose da Silva", "postback_url":"http://requestb.in/1f81u721", "boleto_expiration_date":null, "nsu":null, "payment_method":"credit_card", "card_brand":"visa", "tid":null, "card_last_digits":"4448", "metadata":{ }, "status":"processing", "authorization_code":null, "object":"transaction", "phone":{ "id":13126, "ddi":"55", "object":"phone", "number":"30713261", "ddd":"11" }, "referer":"api_key", "address":{ "city":"S\\u00e3o Paulo", "neighborhood":"Jardim Paulistano", "street_number":"2941", "complementary":"8\\u00ba andar", "country":"Brasil", "object":"address", "zipcode":"01452000", "state":"SP", "street":"Av. Brigadeiro Faria Lima", "id":13236 }, "status_reason":"acquirer", "subscription_id":null, "card":{ "holder_name":"Jose da Silva", "valid":true, "last_digits":"4448", "date_updated":"2014-12-21T01:15:22.000Z", "brand":"visa", "object":"card", "first_digits":"490172", "fingerprint":"2KnrHzAFkjPE", "date_created":"2014-12-21T01:15:21.000Z", "id":"card_ci3xq3kyu0000yd16rihoplu6" }, "soft_descriptor":"Pagamento 1", "customer":{ "name":"John Appleseed", "gender":null, "document_number":"92545278157", "object":"customer", "id":13683, "born_at":null, "date_created":"2014-12-21T01:15:21.000Z", "document_type":"cpf", "email":"*****@*****.**" }, "amount":10000, "boleto_url":null, "antifraud_score":null, "installments":"1", "date_created":"2014-12-22T14:57:59.000Z", "acquirer_response_code":null, "card_first_digits":"490172" }''' httpretty.register_uri( httpretty.POST, self.api_endpoint, body=response, status=200, ) transaction = Transaction( amount='10000', customer=self.customer, postback_url='http://requestb.in/1f81u721', card_hash='card_hash', soft_descriptor='Pagamento 1' ) transaction.charge() self.assertEqual(transaction.data['id'], 173525)
def test_charge_with_metadata(self): response = ''' { "date_updated":"2014-12-22T19:17:09.000Z", "ip":"187.112.12.183", "boleto_barcode":"1234 5678", "cost":0, "refuse_reason":null, "id":173540, "card_holder_name":null, "postback_url":"http://requestb.in/1f81u721", "boleto_expiration_date":"2014-12-29T02:00:00.000Z", "acquirer_name":"development", "nsu":null, "payment_method":"boleto", "card_brand":null, "tid":null, "card_last_digits":null, "metadata":{ "order_id":"123456" }, "status":"waiting_payment", "authorization_code":null, "object":"transaction", "phone":{ "id":13126, "ddi":"55", "object":"phone", "number":"30713261", "ddd":"11" }, "referer":"api_key", "address":{ "city":"S\\u00e3o Paulo", "neighborhood":"Jardim Paulistano", "street_number":"2941", "complementary":"8\\u00ba andar", "country":"Brasil", "object":"address", "zipcode":"01452000", "state":"SP", "street":"Av. Brigadeiro Faria Lima", "id":13236 }, "status_reason":"acquirer", "subscription_id":null, "card":null, "soft_descriptor":null, "customer":{ "name":"John Appleseed", "gender":null, "document_number":"92545278157", "object":"customer", "id":13683, "born_at":null, "date_created":"2014-12-21T01:15:21.000Z", "document_type":"cpf", "email":"*****@*****.**" }, "amount":10000, "boleto_url":"https://pagar.me/", "antifraud_score":null, "installments":1, "date_created":"2014-12-22T19:17:09.000Z", "acquirer_response_code":null, "card_first_digits":null } ''' httpretty.register_uri( httpretty.POST, self.api_endpoint, body=response, status=200, ) transaction = Transaction( amount='10000', customer=self.customer, postback_url='http://requestb.in/1f81u721', payment_method='boleto', metadata=self.metadata ) transaction.charge() self.assertEqual(transaction.data['id'], 173540) self.assertEqual(transaction.data['metadata']['order_id'], '123456')