Guest User

Untitled

a guest
Oct 30th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. import pagarme
  2. import psycopg2
  3.  
  4. pagarme.authentication_key("API_KEY")
  5.  
  6. transaction = pagarme.transaction.find_all()
  7.  
  8. #print(transaction)
  9.  
  10. conn = psycopg2.connect("dbname='DB' user='USER' host='HOST'
  11. password='PASSWORD'")
  12. insert = "INSERT INTO TABELA (object,status) VALUES"
  13.  
  14.  
  15. gravar=[]
  16. for infos in transaction:
  17. gravar.append((
  18. transaction['object'],
  19. transaction['status']
  20. ))
  21. if len(gravar) >0 :
  22. cur = conn.cursor()
  23. y = b','.join(cur.mogrify("(%s,%s)", x) for x in gravar)
  24. comando = insert + y.decode()
  25. try:
  26. cur.execute(comando)
  27. conn.commit()
  28. except (Exception, psycopg2.DatabaseError) as error:
  29. print(error)
  30.  
  31. cur.close()
  32. print('Carga Completa')
  33. else:
  34. conn.close()
  35. print('Nada a Inserir')
  36.  
  37. [
  38. {
  39. "object": "transaction",
  40. "status": "refused",
  41. "refuse_reason": "acquirer",
  42. "status_reason": "acquirer",
  43. "acquirer_response_code": "1011",
  44. "acquirer_name": "pagarme",
  45. "acquirer_id": "5b1eb16fd15fc06256543da4",
  46. "authorization_code": null,
  47. "soft_descriptor": null,
  48. "tid": 59869003,
  49. "nsu": 59869003,
  50. "date_created": "2018-10-30T20:57:01.883Z",
  51. "date_updated": "2018-10-30T20:57:03.655Z",
  52. "amount": 20520,
  53. "authorized_amount": 0,
  54. "paid_amount": 0,
  55. "refunded_amount": 0,
  56. "installments": 1,
  57. "id": 59869003,
  58. "cost": 0,
  59. "card_holder_name": "roberto v raymundo",
  60. "card_last_digits": "5116",
  61. "card_first_digits": "544731",
  62. "card_brand": "mastercard",
  63. "card_pin_mode": null,
  64. "postback_url": null,
  65. "payment_method": "credit_card",
  66. "capture_method": "ecommerce",
  67. "antifraud_score": null,
  68. "boleto_url": null,
  69. "boleto_barcode": null,
  70. "boleto_expiration_date": null,
  71. "referer": "api_key",
  72. "ip": "104.41.14.184",
  73. "subscription_id": null,
  74. "phone": null,
  75. "address": null,
  76. "customer": {
  77. "object": "customer",
  78. "id": 25744747,
  79. "external_id": "3804",
  80. "type": "individual",
  81. "country": "br",
  82. "document_number": null,
  83. "document_type": "cpf",
  84. "name": "Roberto",
  85. "email": "robertocarlosvargas@bol.com.br",
  86. "phone_numbers": [
  87. "+5511999999999"
  88. ],
Add Comment
Please, Sign In to add comment