diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index bf6382fdc..cd285c706 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -174,29 +174,61 @@ class SimplexAPI { void newOrder(SimplexQuote quote) async { try { - // curl --request POST \ - // --url https://sandbox.test-simplexcc.com/wallet/merchant/v2/payments/partner/data \ - // --header 'Authorization: ApiKey XXX' \ - // --header 'accept: application/json' \ - // --header 'content-type: application/json' \ - // -d '{"account_details": {"app_provider_id": "pk_test_XXX", "app_version_id": "123", "app_end_user_id": "01e7a0b9-8dfc-4988-a28d-84a34e5f0a63", "signup_login": {"timestamp": "1994-11-05T08:15:30-05:00", "ip": "207.66.86.226"}}, "transaction_details": {"payment_details": {"quote_id": "3b58f4b4-ed6f-447c-b96a-ffe97d7b6803", "payment_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "order_id": "789", "original_http_ref_url": "https://stackwallet.com/simplex", "destination_wallet": {"currency": "BTC", "address": "bc1qjvj9ca8gdsv3g58yrzrk6jycvgnjh9uj35rja2"}}}}' - - // TODO launch URL which POSTs headers like https://integrations.simplex.com/docs/new-window-payment-form-submission-1 + String version = "123"; // TODO pull from app version variable + String app_end_user_id = + "01e7a0b9-8dfc-4988-a28d-84a34e5f0a63"; // TODO generate per-user ID (pull from wallet?) + String signup_timestamp = + "1994-11-05T08:15:30-05:00"; // TODO supply real signup timestamp (pull from wallet?) + String referral_ip = "207.66.86.226"; // TODO update to API server IP + String payment_id = + "daaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; // TODO make unique and save + String order_id = "789"; // TODO generate unique ID per order + String referrer = "https://stackwallet.com/simplex"; // TODO update + String apiKey = "XXX"; + String publicKey = "pk_test_XXX"; + // Using simplex_api/order; doesn't work: + /* Map headers = { - 'Content-Type': 'application/json', + 'Content-Type': 'application/json' }; String data = - '{"account_details": {"app_end_user_id": "${quote.receivingAddress}"}, "transaction_details": {"digital_currency": "${quote.crypto.ticker.toUpperCase()}", "fiat_currency": "${quote.fiat.ticker.toUpperCase()}", "requested_currency": "USD", "requested_amount": ${quote.youPayFiatPrice}}}'; + '{"account_details": {"app_end_user_id": "${app_end_user_id}"}, "transaction_details": {"payment_details": {"fiat_total_amount": {"currency": "${quote.fiat.ticker.toUpperCase()}", "amount": "${quote.youPayFiatPrice}"}, "requested_digital_amount": {"currency": "${quote.crypto.ticker.toUpperCase()}", "amount": "${quote.youReceiveCryptoAmount}"}, "destination_wallet": {"currency": "${quote.crypto.ticker.toUpperCase()}", "address": "${quote.receivingAddress}"}}'; Uri url = Uri.parse('http://sandbox-api.stackwallet.com/order'); - var res = await http.post(url, headers: headers, body: data); if (res.statusCode != 200) { throw Exception('newOrder exception: statusCode= ${res.statusCode}'); } - final jsonArray = jsonDecode(res.body); + print(jsonArray); + */ + + // Calling Simplex's API manually: + // curl --request POST \ + // --url https://sandbox.test-simplexcc.com/wallet/merchant/v2/payments/partner/data \ + // --header 'Authorization: ApiKey $apiKey' \ + // --header 'accept: application/json' \ + // --header 'content-type: application/json' \ + // -d '{"account_details": {"app_provider_id": "$publicKey", "app_version_id": "123", "app_end_user_id": "01e7a0b9-8dfc-4988-a28d-84a34e5f0a63", "signup_login": {"timestamp": "1994-11-05T08:15:30-05:00", "ip": "207.66.86.226"}}, "transaction_details": {"payment_details": {"quote_id": "3b58f4b4-ed6f-447c-b96a-ffe97d7b6803", "payment_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "order_id": "789", "original_http_ref_url": "https://stackwallet.com/simplex", "destination_wallet": {"currency": "BTC", "address": "bc1qjvj9ca8gdsv3g58yrzrk6jycvgnjh9uj35rja2"}}}}' + + Map headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': 'ApiKey ${apiKey}', + }; + String data = + '{"account_details": {"app_provider_id": "$publicKey", "app_version_id": "$version", "app_end_user_id": "$app_end_user_id", "signup_login": {"timestamp": "$signup_timestamp", "ip": "$referral_ip"}}, "transaction_details": {"payment_details": {"quote_id": "${quote.purchaseId}", "payment_id": "$payment_id", "order_id": "$order_id", "original_http_ref_url": "$referrer", "destination_wallet": {"currency": "${quote.crypto.ticker.toUpperCase()}", "address": "${quote.receivingAddress}"}}}}'; + Uri url = Uri.parse( + 'https://sandbox.test-simplexcc.com/wallet/merchant/v2/payments/partner/data'); + var res = await http.post(url, headers: headers, body: data); + + if (res.statusCode != 200) { + throw Exception('newOrder exception: statusCode= ${res.statusCode}'); + } + final jsonArray = jsonDecode(res.body); + print(jsonArray); + // TODO check if {is_key_required: true} (indicates success) return; } catch (e, s) {