def test_metadata_is_sended_(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         metadata={'sku': 'foo bar'},
     )
     self.assertEqual('foo bar', transaction.get_data()['metadata[sku]'])
 def test_transaction_can_have_any_arguments(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         any_argument='any_value',
     )
     self.assertIn('any_argument', transaction.get_data())
Exemple #3
0
 def test_transaction_can_have_any_arguments(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         any_argument='any_value',
     )
     self.assertIn('any_argument', transaction.get_data())
Exemple #4
0
 def test_metadata_is_sended_(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         metadata={'sku': 'foo bar'},
     )
     self.assertEqual('foo bar', transaction.get_data()['metadata[sku]'])
 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_caputre_later_wihtout_charger(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         capture=False,
     )
     with self.assertRaises(NotBoundException):
         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_transaction_caputre_later(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         capture=False,
     )
     transaction.charge()
     transaction.capture()
Exemple #9
0
 def test_transaction_capture_later_without_charger(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         capture=False,
     )
     with self.assertRaises(NotBoundException):
         transaction.capture()
class TransactionTest(TestCase):
    def setUp(self):
        self.requester = PagarMeRequest(
            'ak_test_KGXIjQ4GicOa2BLGZrDRTR5qNQxDWo')
        self.transaction = Transaction(self.requester)

    def test_build_transaction_attributes_should_be_an_dict(self):
        with self.assertRaises(PagarMeError):
            self.transaction.build_transaction('invalid arg')

    def test_get_transactions(self):
        result = self.transaction.get_transactions()
        self.assertEqual(result.status_code, 200)
    def test_transaction_with_ant_fraud(self):
        customer = Customer(name='foo bar',
                            document_number='11122233345',
                            email='*****@*****.**',
                            address_street='bar foo',
                            address_neighborhood='baz for',
                            address_zipcode='3945154',
                            address_street_number='99',
                            phone_ddd='31',
                            phone_number='9144587')

        transaction = Transaction(api_key='apikey',
                                  amount=314,
                                  card_hash='cardhash',
                                  customer=customer)
        self.assertIn('customer[phone][ddd]', transaction.get_data())
    def test_transaction_with_ant_fraud(self):
        customer = Customer(
            name='foo bar',
            document_number='11122233345',
            email='*****@*****.**',
            address_street='bar foo',
            address_neighborhood='baz for',
            address_zipcode='3945154',
            address_street_number='99',
            phone_ddd='31',
            phone_number='9144587'
        )

        transaction = Transaction(
            api_key='apikey',
            amount=314,
            card_hash='cardhash',
            customer = customer
        )
        self.assertIn('customer[phone][ddd]', transaction.get_data())
    def test_create_transaction_with_split_rules(self):
        
        # Create object split_rules in transaction
        list_split = []
        split_rules = SplitRules(
            recipient_id='re_cihuw6sey005ptq6di0ov6lep',
            charge_processing_fee='true',
            liable='true',
            percentage='70'
        )
        list_split.append(split_rules)
         
        split_rules = SplitRules(
            recipient_id='re_cihuw7xc6004t426er5llvqds',
            charge_processing_fee='true',
            liable='true',
            percentage='30'
        )
        list_split.append(split_rules)        
        
        customer = Customer(
            name='foo bar',
            document_number='11122233345',
            email='*****@*****.**',
            address_street='bar foo',
            address_neighborhood='baz for',
            address_zipcode='3945154',
            address_street_number='99',
            phone_ddd='31',
            phone_number='9144587'
        )

        transaction = Transaction(
            api_key='apikey',
            amount=314,
            card_hash='cardhash',
            customer = customer,
            split_rules = list_split,
        )
        self.assertIn('customer[phone][ddd]', transaction.get_data())
Exemple #14
0
 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)
Exemple #15
0
 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()
Exemple #16
0
 def test_transaction_capture_later(self):
     transaction = Transaction(
         api_key='apikey',
         amount=314,
         card_hash='cardhash',
         capture=False,
     )
     transaction.charge()
     transaction.capture()
 def test_refund_transaction_fail(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     with self.assertRaises(PagarmeApiError):
         transaction.refund()
 def test_refund_transaction_before_set_id(self):
     transaction = Transaction(api_key='apikey')
     with self.assertRaises(NotPaidException):
         transaction.refund()
 def test_refund_transaction(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     transaction.refund()
     self.assertEqual('refunded', transaction.status)
 def test_get_transaction_by_id_fails(self):
     transaction = Transaction(api_key='apikey')
     with self.assertRaises(PagarmeApiError):
         transaction.find_by_id(314)
 def test_get_transaction_by_id(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     self.assertEqual(314, transaction.id)
Exemple #22
0
 def test_refund_transaction_before_set_id(self):
     transaction = Transaction(api_key='apikey')
     with self.assertRaises(NotPaidException):
         transaction.refund()
    def test_find_by_id(self):
        response = '''
        {
            "date_updated":"2014-12-22T15:09:03.000Z",
            "ip":"187.112.12.183",
            "boleto_barcode":null,
            "cost":260,
            "refuse_reason":null,
            "id":173526,
            "card_holder_name":"Jose da Silva",
            "postback_url":"http://requestb.in/1f81u721",
            "boleto_expiration_date":null,
            "acquirer_name":"development",
            "nsu":1419260943444,
            "payment_method":"credit_card",
            "card_brand":"visa",
            "tid":1419260943444,
            "card_last_digits":"4448",
            "metadata":{

            },
            "status":"paid",
            "authorization_code":"564326",
            "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 2",
            "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":71.86,
            "installments":1,
            "date_created":"2014-12-22T15:09:03.000Z",
            "acquirer_response_code":"00",
            "card_first_digits":"490172"
        }
        '''

        httpretty.register_uri(
            httpretty.GET,
            self.api_endpoint + '/173526',
            body=response,
            status=200,
        )

        transaction = Transaction()
        transaction.find_by_id(173526)
        self.assertEqual(transaction.data['id'], 173526)
Exemple #24
0
 def test_get_transaction_by_id(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     self.assertEqual(314, transaction.id)
 def test_transaction_caputre_later_fails(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     with self.assertRaises(PagarmeApiError):
         transaction.capture()
    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')
Exemple #27
0
 def test_transaction_capture_later_fails(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     with self.assertRaises(PagarmeApiError):
         transaction.capture()
Exemple #28
0
 def test_refund_transaction_fail(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     with self.assertRaises(PagarmeApiError):
         transaction.refund()
 def test_get_split_rules_by_id_transaction(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_split_rule(0000)
     self.assertEqual(314, transaction.id)
     
     
 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)
Exemple #31
0
 def test_get_transaction_by_id_fails(self):
     transaction = Transaction(api_key='apikey')
     with self.assertRaises(PagarmeApiError):
         transaction.find_by_id(314)
 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 setUp(self):
     self.requester = PagarMeRequest(
         'ak_test_KGXIjQ4GicOa2BLGZrDRTR5qNQxDWo')
     self.transaction = Transaction(self.requester)
Exemple #34
0
 def test_refund_transaction(self):
     transaction = Transaction(api_key='apikey')
     transaction.find_by_id(314)
     transaction.refund()
     self.assertEqual('refunded', transaction.status)