Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter support #28

Open
MedNewton opened this issue Jan 8, 2023 · 1 comment
Open

Flutter support #28

MedNewton opened this issue Jan 8, 2023 · 1 comment

Comments

@MedNewton
Copy link

Can the sdk be integrated in flutter in any possible way ? (Http requests maybe ?)

@tahabasri
Copy link

Basically you'll need to communicate with YouCanPay endpoint, you can code a similar functionality in Flutter, here is a quick sample in Java for generating tokens (for reference only):

public class Main {

    static boolean sandboxMode = true;
    static String url = "https://youcanpay.com/" + (sandboxMode ? "sandbox/api/" : "api/");

    public static void main(String[] args) throws Exception {
        OkHttpClient client = new OkHttpClient();

        // Create JSON request body
        MediaType JSON = MediaType.get("application/json; charset=utf-8");

        Map<String, Object> params = new HashMap<>();
        params.put("pri_key", "<PRIVATE_KEY>");
        params.put("amount", "100.0");
        params.put("currency", "USD");
        params.put("order_id", "123");
        params.put("customer_ip", "127.0.0.1");

        ObjectMapper objectMapper = new ObjectMapper();
        String jsonString = objectMapper.writeValueAsString(params);
        System.out.println("JSON String: " + jsonString);

        RequestBody requestBody = RequestBody.create(jsonString, JSON);

        // Build the request
        Request request = new Request.Builder()
                .url(url + "tokenize")
                .post(requestBody)
                .build();

        // Execute the request and handle the response
        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                // Get the response body
                String responseBody = response.body().string();
                System.out.println("Response Body: " + responseBody);
            } else {
                System.out.println("Error: " + response.code() + " " + response.message());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants