<commit_before>import React, { Component } from 'react';
import { Container, Row, Col, Button, Table, Alert } from 'reactstrap';
import styles from './Checkout.styl';
import { actions, store } from './../../../flux';
import Numeral from './../../../helpers/Numeral';
import classNames from 'classnames';
import pagarme from 'pagarme';
import { Redirect } from 'react-router-dom';
import Loading from './Loading';
import { ToastContainer, ToastMessage } from 'react-toastr';
const ToastMessageFactory = React.createFactory(ToastMessage.animation);

export default class Checkout extends Component {
  constructor() {
    super();
    this.state = { loading: false };
  }

  componentDidMount() {
    const gamesList = store.checkout.getGamesList();
    const amount = gamesList.length;
    const totalPrice = this.calculateTotalPrice(gamesList);

    this.setState({
      gamesList,
      amount,
      totalPrice
    });
  }

  calculateTotalPrice(gamesList) {
    const totalPrice = gamesList.reduce(
      (prevVal, elem) => prevVal + elem.price,
      0
    );

    return totalPrice;
  }

  parseToCents(value) {
    value *= 100;
    value = parseInt(value.toFixed(0));

    return value;
  }

  makePagarmeTransaction() {
    let { totalPrice } = this.state;

    totalPrice = this.parseToCents(totalPrice);

    this.setState({ loading: true });

    pagarme.client
      .connect({ api_key: '<KEY>' })
      .then(client =>
        client.transactions
          .create({
            amount: totalPrice,
            customer: {
              external_id: '#3311',
              name: '<NAME>',
              type: 'individual',
              country: 'br',
              email: '<EMAIL>',
              documents: [
                {
                  type: 'cpf',
                  number: '00000000000'
                }
              ],
              phone_numbers: ['+5511999998888', '+5511888889999'],
              birthday: '1965-01-01'
            },
            billing: {
              name: '<NAME>',
              address: {
                country: 'br',
                state: 'sp',
                city: 'Cotia',
                neighborhood: 'Rio Cotia',
                street: 'Rua Matrix',
                street_number: '9999',
                zipcode: '06714360'
              }
            },
            items: [
              {
                id: 'r123',
                title: 'Red pill',
                unit_price: 10000,
                quantity: 1,
                tangible: true
              },
              {
                id: 'b123',
                title: 'Blue pill',
                unit_price: 10000,
                quantity: 1,
                tangible: true
              }
            ],
            card_number: '4111111111111111',
            card_holder_name: 'abc',
            card_expiration_date: '1225',
            card_cvv: '123',
            split_rules: [
              {
                recipient_id: 're_cj83vzn8y02p4jb6exgeepjvn',
                percentage: 60,
                liable: true,
                charge_processing_fee: true
              },
              {
                recipient_id: 're_cj83vxw0z02l0jp6etrgf6y2q',
                percentage: 25,
                liable: true,
                charge_processing_fee: true
              },
              {
                recipient_id: 're_cj83vz1ce02giof6dyduizo7b',
                percentage: 15,
                liable: true,
                charge_processing_fee: true
              }
            ]
          })
          .then(res => {
            actions.transaction
              .registerTransaction(res)
              .then(() => {
                this.redirectToDone();
              })
              .catch(() => {
                this.redirectToDone();
              });
          })
          .catch(() => {
            this.setState({ loading: false });
            this.showNotification('Erro', 'Pedido não concluido', 'error');
          })
      );
  }
<commit_msg>Modificando objeto para enviar na transacao do pagarme<commit_after>import React, { Component } from 'react';
import { Container, Row, Col, Button, Table, Alert } from 'reactstrap';
import styles from './Checkout.styl';
import { actions, store } from './../../../flux';
import Numeral from './../../../helpers/Numeral';
import classNames from 'classnames';
import pagarme from 'pagarme';
import { Redirect } from 'react-router-dom';
import Loading from './Loading';
import { ToastContainer, ToastMessage } from 'react-toastr';
const ToastMessageFactory = React.createFactory(ToastMessage.animation);

export default class Checkout extends Component {
  constructor() {
    super();
    this.state = { loading: false };
  }

  componentDidMount() {
    const gamesList = store.checkout.getGamesList();
    const amount = gamesList.length;
    const totalPrice = this.calculateTotalPrice(gamesList);

    this.setState({
      gamesList,
      amount,
      totalPrice
    });
  }

  calculateTotalPrice(gamesList) {
    const totalPrice = gamesList.reduce(
      (prevVal, elem) => prevVal + elem.price,
      0
    );

    return totalPrice;
  }

  parseToCents(value) {
    value *= 100;
    value = parseInt(value.toFixed(0));

    return value;
  }

  createTransactionItems(gamesList) {
    const items = gamesList.map(({ id, name, price }) => {
      price = this.parseToCents(price);

      return {
        id: id.toString(),
        title: name,
        unit_price: price,
        quantity: 1,
        tangible: true
      };
    });

    return items;
  }

  makePagarmeTransaction() {
    let { totalPrice, gamesList } = this.state;
    const items = this.createTransactionItems(gamesList);

    totalPrice = this.parseToCents(totalPrice);

    this.setState({ loading: true });

    let transactionObj = {
      amount: totalPrice,
      customer: {
        external_id: '#3311',
        name: '<NAME>',
        type: 'individual',
        country: 'br',
        email: '<EMAIL>',
        documents: [
          {
            type: 'cpf',
            number: '00000000000'
          }
        ],
        phone_numbers: ['+5511999998888', '+5511888889999'],
        birthday: '1965-01-01'
      },
      billing: {
        name: '<NAME>',
        address: {
          country: 'br',
          state: 'sp',
          city: 'Cotia',
          neighborhood: 'Rio Cotia',
          street: 'Rua Matrix',
          street_number: '9999',
          zipcode: '06714360'
        }
      },
      card_number: '4111111111111111',
      card_holder_name: 'abc',
      card_expiration_date: '1225',
      card_cvv: '123',
      split_rules: [
        {
          recipient_id: 're_cj83vzn8y02p4jb6exgeepjvn',
          percentage: 60,
          liable: true,
          charge_processing_fee: true
        },
        {
          recipient_id: 're_cj83vxw0z02l0jp6etrgf6y2q',
          percentage: 25,
          liable: true,
          charge_processing_fee: true
        },
        {
          recipient_id: 're_cj83vz1ce02giof6dyduizo7b',
          percentage: 15,
          liable: true,
          charge_processing_fee: true
        }
      ]
    };
    transactionObj['items'] = items;

    pagarme.client
      .connect({ api_key: '<KEY>' })
      .then(client =>
        client.transactions
          .create(transactionObj)
          .then(res => {
            actions.transaction
              .registerTransaction(res)
              .then(() => {
                this.redirectToDone();
              })
              .catch(() => {
                this.redirectToDone();
              });
          })
          .catch(() => {
            this.setState({ loading: false });
            this.showNotification('Erro', 'Pedido não concluido', 'error');
          })
      );
  }

{'fraction_non_alphanumeric': 0.12038461538461538, 'fraction_numerical': 0.032692307692307694, 'mean_word_length': 1.6064149682592717, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4141629', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2198, 'n_words': 464}