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.
It would be better if you post the code and not just an image.
– Sorack
I changed the question: by entering the code.
– alexjosesilva
You defined
sale
asSale
, but apparently the return of its operations is aSaleResponse
. Have you seen in the documentation to confirm if you’re doing it right?– Woss
You probably have to create an object of the type
SaleResponse
and store in it the return of the linesnew CieloEcommerce(merchant...)
.– StatelessDev
when I use Saleresponse I lose the method String paymentId = sale.getPayment(). getPaymentId();
– alexjosesilva
@Andersoncarloswoss documentation fails at developer level
– alexjosesilva
@Statelessdev when using Saleresponse I lose method String paymentId = sale.getPayment(). getPaymentId();
– alexjosesilva
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 methodscaptureSale()
andcancelSale()
and check if it is possible to return in some other class that has the method you need.– StatelessDev
I have the github manual: https://github.com/DeveloperCielo/API-3.0-Java
– alexjosesilva
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.
– Jeferson Lemos