Menu

Post image 1
Post image 2
1 / 2
0

Building a Payment Processor: My First Attempt Was a Disaster

DEV Community·Oreoluwa Bimbo-Salami·about 1 month ago
#397oLczl
Reading 0:00
15s threshold

I wanted to figure out how people build payment systems without losing everyone's money. It turns out, my first attempt was a great way to lose a lot of it. I started with what felt like a simple Go service. One endpoint, one database table, and a third-party provider to handle the actual charging. The plan was straightforward: Decode the request. Call the provider to charge the user. Save the result to my database. Respond with a 201. It looked like this: func ( s Server ) createCharge ( w http . ResponseWriter , r * http . Request ) { ctx := r . Context () var req createChargeRequest if err := decodeJSON ( r , & req ); err != nil { writeError ( w , http . StatusBadRequest , err . Error ()) return } // 1. Charge the user if err := s . paymentProvider . Charge ( ctx , provider . CreateCharge { Amount : req . Amount , Currency : req . Currency , Reference : req . Reference , }); err != nil { writeError ( w , http . StatusBadRequest , err . Error ()) return } // 2. Record it in the DB c , err := s .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More