-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add payment gateway grpc protocol
- Loading branch information
1 parent
268c7f9
commit 2f5ddb7
Showing
8 changed files
with
563 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as grpc from '@grpc/grpc-js'; | ||
import * as protoLoader from '@grpc/proto-loader'; | ||
import path from 'path'; | ||
import PaymentGateway, { Input, Output } from '../../../application/gateways/Payment'; | ||
import { TransactionStatus } from '../../../domain/entities/Transaction'; | ||
|
||
const protoObject = protoLoader.loadSync(path.resolve(__dirname, 'payment.proto')); | ||
const payment = grpc.loadPackageDefinition(protoObject) as any; | ||
|
||
export default class PaymentGatewayGrpc implements PaymentGateway { | ||
private readonly client: any; | ||
|
||
constructor( | ||
private readonly serverUrl: string | ||
) { | ||
this.client = new payment.PaymentService(this.serverUrl, grpc.credentials.createInsecure()); | ||
} | ||
|
||
async createTransaction(input: Input): Promise<Output> { | ||
return new Promise((resolve, reject) => { | ||
this.client.pay(input, (err: any, response: any) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve({ | ||
tid: response.tid, | ||
status: response.status === 'confirmed' ? TransactionStatus.CONFIRMED : TransactionStatus.RECUSED | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
|
||
service PaymentService { | ||
rpc Pay(PaymentItem) returns (PaymentResponseItem) {} | ||
} | ||
|
||
message PaymentItem { | ||
float value = 1; | ||
string creditCardToken = 2; | ||
} | ||
|
||
message PaymentResponseItem { | ||
string tid = 1; | ||
string status = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.