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

fix: added ticket_id to razorpay order_notes #3

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub async fn generate_order(
notes_key_1: id.clone(),
notes_key_2: payload.ticket_type.clone(),
notes_key_3: "RCSCTF2024".to_string(),
notes_key_4: None,
}
};

Expand Down Expand Up @@ -103,7 +104,7 @@ pub async fn check_payments(
headers.insert("Authorization", format!("Basic {}", encoded_key).parse().unwrap());

let request = client.request(reqwest::Method::GET, format!("https://api.razorpay.com/v1/orders/{}", order_id))
.headers(headers);
.headers(headers.clone());

let response = request.send().await.unwrap();
if response.status() != StatusCode::OK {
Expand All @@ -119,7 +120,7 @@ pub async fn check_payments(
Statement::with_args("UPDATE ticket set is_paid = true, ticket_id = ? WHERE id = ?", args![ticket_id.clone(), order.notes.notes_key_1.clone()])
).await.unwrap();
let ticket = sql_client.execute(
Statement::with_args("SELECT email, name, ticket_type FROM ticket WHERE id = ?", args![order.notes.notes_key_1])
Statement::with_args("SELECT email, name, ticket_type, id FROM ticket WHERE id = ?", args![order.notes.notes_key_1])
).await.unwrap();
let ticket = ticket.rows;
let ticket = ticket[0].clone();
Expand All @@ -128,12 +129,29 @@ pub async fn check_payments(
payee_name: ticket.values[1].clone().to_string(),
payee_ticket_id: ticket_id.clone(),
ticket_type: ticket.values[2].clone().to_string(),
id: ticket.values[3].clone().to_string(),
};
let mailer_auth = MailerAuth {
username: state.env_store.mailer_username.clone(),
password: state.env_store.mailer_password.clone(),
mailer_url: state.env_store.mailer_url.clone(),
};
let updated_notes = CreateOrderNotes {
notes_key_1: ticket.id.clone(),
notes_key_2: ticket.ticket_type.clone(),
notes_key_3: "RCSCTF2024".to_string(),
notes_key_4: Some(ticket_id.clone()),
};

let request = client.request(reqwest::Method::PATCH, format!("https://api.razorpay.com/v1/orders/{}", order_id))
.headers(headers)
.json(&updated_notes);

let response = request.send().await.unwrap();
if response.status() != StatusCode::OK {
return format!("FAIL!");
}

let mailer = send_ticket(ticket, mailer_auth).await;
return mailer
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub struct CreateOrderRequest {
pub struct CreateOrderNotes {
pub notes_key_1: String,
pub notes_key_2: String,
pub notes_key_3: String
pub notes_key_3: String,
pub notes_key_4: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand All @@ -81,6 +82,7 @@ pub struct CreateTicketMailingRequest {
pub payee_email: String,
pub payee_ticket_id: String,
pub ticket_type: String,
pub id: String,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
Loading