Skip to content

Commit

Permalink
feature: Added payment for vault
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantiago2719 committed Dec 9, 2023
1 parent 83e02a5 commit 7b342db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion payment-vault/src/payment.rs
Expand Up @@ -114,7 +114,7 @@ pub struct MetaData {

#[derive(Debug, Serialize)]
#[allow(non_snake_case)]
struct Payment {
pub struct Payment {
paymentTokenId: String,
totalAmount: TotalAmount,
buyer: Buyer,
Expand Down
38 changes: 15 additions & 23 deletions payment-vault/src/payment/payment_gateway.rs
Expand Up @@ -9,29 +9,9 @@ pub trait PaymentGateway {
async fn create_payment_token(&self, card_details: CardDetails) -> Result<Response, Error>;

/// Returns a response that contains the details of the payment transaction
async fn create_payment(&self) -> Result<Response, Box<dyn std::error::Error>>;
async fn create_payment(&self, payment: Payment) -> Result<Response, Error>;
}

#[allow(non_snake_case)]
impl Payment {
fn new(
paymentTokenId: String,
TotalAmount: TotalAmount,
buyer: Buyer,
redirectUrl: RedirectUrl,
requestReferenceNumber: String,
metadata: Option<MetaData>,
) -> Payment {
Payment {
paymentTokenId,
totalAmount: TotalAmount,
buyer,
redirectUrl,
requestReferenceNumber,
metadata,
}
}
}
/// Implement the PaymentGateway trait to MayaClient
#[async_trait]
impl PaymentGateway for MayaClient {
Expand Down Expand Up @@ -91,7 +71,19 @@ impl PaymentGateway for MayaClient {
.await
}

async fn create_payment(&self) -> Result<Response, Box<dyn std::error::Error>> {
todo!();
async fn create_payment(&self, payment: Payment) -> Result<Response, Error> {
let url = format!("https://{}/payments/v1/payments", self.url_domain);

let auth = format!("Basic {}", &self.auth_header);
let request_body = payment;

self.client
.post(&url)
.header(AUTHORIZATION, auth)
.header(ACCEPT, "application/json")
.header(CONTENT_TYPE, "application/json")
.json(&request_body)
.send()
.await
}
}

0 comments on commit 7b342db

Please sign in to comment.