Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshjosh361 committed Oct 14, 2024
1 parent 7dc39fa commit b82b98d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion payment-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.env.env
*.env
6 changes: 1 addition & 5 deletions payment-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# First stage: Build the Go binary
FROM golang:1.22.2-alpine AS builder

# Set the working directory inside the builder stage

WORKDIR /app

# Copy go.mod and go.sum to cache dependencies
COPY go.mod ./
COPY go.sum ./
RUN go mod download

# Copy the rest of the application files
COPY . .

# Build the Go app as a statically linked binary
Expand All @@ -24,8 +22,6 @@ WORKDIR /root/
# Copy the Go binary from the builder stage
COPY --from=builder /app/main .

# Expose port 8082
EXPOSE 8082

# Run the Go binary
CMD ["./main"]
8 changes: 5 additions & 3 deletions payment-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
services:
mongo:
container_name: mongo
container_name: mongo-payment
image: mongo:latest
restart: always
ports:
- "27019:27017"
- "27017:27017"

goapp:
build: .
container_name: goapp
container_name: goapp-payment
env_file:
- .env
ports:
- "8082:8082"
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion payment-service/internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (p *PaymentData) SavePayment(ctx context.Context, payment *model.Payment) e
func (p *PaymentData) GetPaymentById(ctx context.Context, id primitive.ObjectID) (*model.Payment, error) {

var payment *model.Payment
err := p.Collection.FindOne(ctx, bson.M{"id": id}).Decode(&payment)
err := p.Collection.FindOne(ctx, bson.M{"_id": id}).Decode(&payment)
if err != nil {
return nil, err
}
Expand Down
15 changes: 5 additions & 10 deletions payment-service/internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@ import (
"os"
"time"

"github.com/joho/godotenv"
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/paymentintent"
"go.mongodb.org/mongo-driver/bson/primitive"
)

// load env variables
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}

type PaymentService struct {
paymentData *data.PaymentData
}
Expand All @@ -37,8 +28,12 @@ func (ps *PaymentService) ProcessPayment(ctx context.Context, payment *model.Pay
payment.CreatedAt = time.Now()
payment.UpdatedAt = time.Now()

STRIPE_API := os.Getenv("STRIPE_API")
if STRIPE_API == "" {
log.Fatal("failed to get stripe api env")
}
// stripe api client
stripe.Key = os.Getenv("STRIPE_API")
stripe.Key = STRIPE_API

// Creating a stripe payment intent
params := &stripe.PaymentIntentParams{
Expand Down

0 comments on commit b82b98d

Please sign in to comment.