I’m doing an integration with Cielo’s api but I get an error message:

Asked

Viewed 542 times

0

I’m doing an integration with api-Cielo 3.0 but I’m getting an error message:

application code

package cieloecommerce.sdk.ecommerce;

import java.io.IOException;

import cieloecommerce.sdk.Merchant;
import cieloecommerce.sdk.ecommerce.Sale;
import cieloecommerce.sdk.ecommerce.Payment;
import cieloecommerce.sdk.ecommerce.CreditCard;
import cieloecommerce.sdk.ecommerce.CieloEcommerce;
import cieloecommerce.sdk.ecommerce.Environment;

import cieloecommerce.sdk.ecommerce.request.CieloError;
import cieloecommerce.sdk.ecommerce.request.CieloRequestException;

public class Teste1 {

    public static void main(String[] args) {
        String MerchantID  = "123";
        String MerchantKey = "123";

        // Configure seu merchant
        Merchant merchant = new Merchant(MerchantID, MerchantKey);

        // Crie uma instância de Sale informando o ID do pagamento
        Sale sale = new Sale("123");

        // Crie uma instância de Customer informando o nome do cliente
        Customer customer = sale.customer("alex jose");

        // Crie uma instância de Payment informando o valor do pagamento
        Payment payment = sale.payment(1);

        // Crie  uma instância de Credit Card utilizando os dados de teste
        // esses dados estão disponíveis no manual de integração
        payment.creditCard("123", "MasterCard").setExpirationDate("11/2021")
                                         .setCardNumber("123123123")
                                         .setHolder("Fulano de Tal");

        // Crie o pagamento na Cielo
        try {
            // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda
            sale = new CieloEcommerce(merchant, Environment.SANDBOX).createSale(sale);

            // Com a venda criada na Cielo, já temos o ID do pagamento, TID e demais
            // dados retornados pela Cielo
            String paymentId = sale.getPayment().getPaymentId();

            // Com o ID do pagamento, podemos fazer sua captura, se ela não tiver sido capturada ainda
            sale = new CieloEcommerce(merchant, Environment.SANDBOX).captureSale(paymentId, 15700, 0);

            // E também podemos fazer seu cancelamento, se for o caso
            sale = new CieloEcommerce(merchant, Environment.SANDBOX).cancelSale(paymentId, 15700);
        } catch (CieloRequestException e) {
            // Em caso de erros de integração, podemos tratar o erro aqui.
            // os códigos de erro estão todos disponíveis no manual de integração.
            CieloError error = e.getError();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

Exception in thread "main" java.lang.Error: Unresolved Compilation problems: Type Mismatch: cannot Convert from Saleresponse to Sale Type Mismatch: cannot Convert from Saleresponse to Sale

cieloecommerce.sdk.Ecommerce.Teste1.main(Teste1.java:49)

I downloaded the sdk from the site and imported as Maven project. I tried to make a purchase according to the manual but I received the message above.

inserir a descrição da imagem aqui

  • It would be better if you post the code and not just an image.

  • I changed the question: by entering the code.

  • 1

    You defined sale as Sale, but apparently the return of its operations is a SaleResponse. Have you seen in the documentation to confirm if you’re doing it right?

  • You probably have to create an object of the type SaleResponse and store in it the return of the lines new CieloEcommerce(merchant...).

  • when I use Saleresponse I lose the method String paymentId = sale.getPayment(). getPaymentId();

  • @Andersoncarloswoss documentation fails at developer level

  • @Statelessdev when using Saleresponse I lose method String paymentId = sale.getPayment(). getPaymentId();

  • Well, it will be difficult for someone to help you. The error is quite clear, you will not be able to play the return of the method in this class Sale. It remains for you to read the documentation, especially in these methods captureSale() and cancelSale() and check if it is possible to return in some other class that has the method you need.

  • I have the github manual: https://github.com/DeveloperCielo/API-3.0-Java

  • In the documentation it is missing a variable, to solve the error, one must create the variable of type Updatesaleresponse and with it use in the methods in which it is accusing error.

Show 5 more comments

1 answer

1


I’m implementing this same code in Android Studio.

I replaced sale for:

UpdateSaleResponse response = new CieloEcommerce(merchant, Environment.SANDBOX).captureSale(paymentId, 15700, 0);

I think both captureSale how much cancelSale is to be used in a separate function of the createSale. For example:

private void RetrievePurchaseInfo() {
        try {
            UpdateSaleResponse response = new CieloEcommerce(merchant, Environment.SANDBOX).captureSale(paymentId, 15700, 0);
            Log.i(TAG, "Response is "+response.getReturnCode());
            Log.i(TAG, "Provider return code is "+response.getProviderReturnCode());
            Log.i(TAG, "Provider return message is "+response.getProviderReturnMessage());
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (CieloRequestException e) {
            e.printStackTrace();
        }

    }

Anyway, I started to implement today for the first time and I still don’t know all the features.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.