Init & create payment (not working)

This commit is contained in:
Adrian Woźniak 2022-12-09 17:01:16 +01:00
parent 9775274d71
commit 8d17fb9309
2 changed files with 23 additions and 4 deletions

View File

@ -117,6 +117,10 @@ impl PayU {
} }
fn create_payment(c: CreatePayment) -> Result<res::CreateOrder, Error> { fn create_payment(c: CreatePayment) -> Result<res::CreateOrder, Error> {
eprintln!("Authorizing...");
authorize()?;
eprintln!("Authorized!");
let config = client(); let config = client();
let pay_u = config.lock().unwrap(); let pay_u = config.lock().unwrap();
@ -158,6 +162,7 @@ fn create_payment(c: CreatePayment) -> Result<res::CreateOrder, Error> {
description, description,
) )
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
Error::MalformedCreatePayment Error::MalformedCreatePayment
})? })?
@ -172,7 +177,7 @@ fn create_payment(c: CreatePayment) -> Result<res::CreateOrder, Error> {
.with_notify_url(notify_uri) .with_notify_url(notify_uri)
.with_continue_url(continue_uri); .with_continue_url(continue_uri);
authorize()?; eprintln!("calling host http 'create order'!");
let res = wapc::host_call( let res = wapc::host_call(
"binding", "binding",
"http:req", "http:req",
@ -187,11 +192,13 @@ fn create_payment(c: CreatePayment) -> Result<res::CreateOrder, Error> {
.unwrap(), .unwrap(),
) )
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
Error::PaymentFailed Error::PaymentFailed
}) })
.and_then(|v| { .and_then(|v| {
deserialize(&v).map_err(|e| { deserialize(&v).map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
Error::PaymentFailed Error::PaymentFailed
}) })
@ -219,6 +226,7 @@ fn authorize() -> Result<bool, Error> {
expires_in: i64, expires_in: i64,
} }
eprintln!("calling host http 'authorize'!");
let res = wapc::host_call("binding", "http:req", "http_req", &serialize(HttpRequest { let res = wapc::host_call("binding", "http:req", "http_req", &serialize(HttpRequest {
method: HttpMethod::Post, method: HttpMethod::Post,
url: format!( url: format!(
@ -230,16 +238,20 @@ fn authorize() -> Result<bool, Error> {
bearer_auth: None, bearer_auth: None,
body: None, body: None,
}).map_err(|e| { }).map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
Error::PaymentFailed Error::PaymentFailed
})?).map_err(|e| { })?).map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
Error::PaymentFailed Error::PaymentFailed
})?; })?;
let res: BearerResult = deserialize(&res).map_err(|e| { let res: BearerResult = deserialize(&res).map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
Error::PaymentFailed Error::PaymentFailed
})?; })?;
eprintln!("Authorized with calling host");
tracing::trace!("Bearer is {}", res.access_token); tracing::trace!("Bearer is {}", res.access_token);
pay_u.bearer_expires_at = Utc::now() + Duration::seconds(res.expires_in); pay_u.bearer_expires_at = Utc::now() + Duration::seconds(res.expires_in);
pay_u.bearer = Some(res.access_token); pay_u.bearer = Some(res.access_token);

View File

@ -33,6 +33,7 @@ impl UpdateConfig for Opts {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
tracing_subscriber::fmt::init();
let opts: Opts = gumdrop::parse_args_default_or_exit(); let opts: Opts = gumdrop::parse_args_default_or_exit();
let config = config::default_load(&opts); let config = config::default_load(&opts);
@ -180,11 +181,13 @@ fn http_request(req: HttpRequest) -> Result<Vec<u8>, payment_adapter::Error> {
.bearer_auth(bearer) .bearer_auth(bearer)
.send() .send()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})? })?
.text() .text()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})?; })?;
@ -196,11 +199,13 @@ fn http_request(req: HttpRequest) -> Result<Vec<u8>, payment_adapter::Error> {
.headers(headers) .headers(headers)
.send() .send()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})? })?
.text() .text()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})?; })?;
@ -208,9 +213,7 @@ fn http_request(req: HttpRequest) -> Result<Vec<u8>, payment_adapter::Error> {
} }
(HttpMethod::Post, Some(bearer)) => { (HttpMethod::Post, Some(bearer)) => {
let body = body.unwrap_or_default(); let body = body.unwrap_or_default();
let len = body.len(); let body = reqwest::blocking::Body::from(body);
let body = std::io::Cursor::new(body);
let body = reqwest::blocking::Body::sized(body, len as u64);
let text = client let text = client
.post(url) .post(url)
.headers(headers) .headers(headers)
@ -218,11 +221,13 @@ fn http_request(req: HttpRequest) -> Result<Vec<u8>, payment_adapter::Error> {
.body(body) .body(body)
.send() .send()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})? })?
.text() .text()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})?; })?;
@ -235,11 +240,13 @@ fn http_request(req: HttpRequest) -> Result<Vec<u8>, payment_adapter::Error> {
.body(body.unwrap_or_default()) .body(body.unwrap_or_default())
.send() .send()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})? })?
.text() .text()
.map_err(|e| { .map_err(|e| {
eprintln!("{}", e);
tracing::error!("{}", e); tracing::error!("{}", e);
payment_adapter::Error::HttpFailed payment_adapter::Error::HttpFailed
})?; })?;