简体   繁体   English

Node.js和MongoDB中的Payment GateWay集成

[英]Payment GateWay integration in nodejs and mongodb

Hi I am Integration Payment GateWay to my app but i am stuck. 嗨,我是我的应用程序的Integration Payment GateWay,但是我被卡住了。 for cod(Cash On Delivery) mode of payment it is working fine.but while in integration online payment gateway it is giving bit pain like i am creating payment link using instamojo when link is created successful; 对于鳕鱼(货到付款)付款方式,它可以正常工作。但是在集成在线付款网关时,它给我带来一点痛苦,例如我在成功创建链接后使用instamojo创建了付款链接; i return that payment link to client and redirect user to that link 我将该付款链接返回给客户,并将用户重定向到该链接

1 if user fills card details successfully and instamojo hits my provided webhook(post url) with payment details 2 what if user cancels tab or doesn't pays 1如果用户成功填写卡详细信息并且instamojo击中我提供的带有付款详细信息的webhook(发布网址)2如果用户取消标签或不付款怎么办

question here is where shall in create order in database. 这里的问题是数据库中创建顺序应该在哪里。 if it is to be created on placeorder url of my app then i need to set order status incomplete and run a cron job for second condition (because order is already created and webhook is not hit by intamojo). 如果要在我的应用的下单网址上创建,则我需要将订单状态设置为不完整,并针对第二种情况运行cron作业(因为已经创建了订单,并且intamojo不会打击webhook)。 is it right way to do or there is other better ways to handle all this 这是正确的方法还是还有其他更好的方法来处理所有这些问题

Promise.all([getUpdatedCart(userId), findUser(userId), getDiscount(userId,couponCode)])
                .then(function(resultArray) {
                    var cart = resultArray[0];
                    var user = resultArray[1];
                    var discountAmount = resultArray[2];
                    var offerId=null;
                    if (!cart)
                        return sendResponse(response,400,"error","Cart Not Found");
                    if (discountAmount>0) 
                        var offerId=getOfferId(couponCode);
                    var order = {
                        user: user._id,
                        cart: cart._id,
                        shippingAddress:shippingAddressId,
                        billingAddress:billingAddressId,
                        paymenMethod: paymentMethod,
                        offer:offerId,
                        deliveryNote:deliveryNote,
                        amount:cart.amount
                    };

                    var newOrder = Order(order);
                    if (paymentMethod==='cod') 
                        newOrder.save(function(error,order){
                            if (!error)
                                if (order){
                                    Cart.expireCart(cart._id);
                                    return sendResponse(response,201,"success",order);
                                }

                        });
                    else if(paymentMethod==='intamojo'){
                        var purpose='Order Number-'+ newOrder.id;
                        Instamojo.setHeaders(InstaConfig.test.API_KEY, InstaConfig.test.API_AUTH_TOKEN);
                        var amountPayable = cart.amount - discountAmount;
                        var data = generatePayload(user, purpose, amountPayable);
                        Instamojo.createPaymentLink(data, function(error, resultResponse, body) {
                            if (resultResponse && body && resultResponse.statusCode===201)
                                return sendResponse(response,200,"success",body.longUrl+"?embed=form");
                        });
                    }
                    else if(paymentMethod==='payumoney'){

                    }
                    else
                        return sendResponse(response,400,"error","Invalid Mode of Payment");

                })      
                .catch(function(error) {
                    return sendResponse(response,400,"error",error);
                });

Can anyone Please help if i need to write cron job kindly suggest library for that 任何人都可以帮忙吗,如果我需要编写cron作业,请为此提供建议库

You need not create a cron job. 您无需创建cron作业。

You can create Order in your database first, and then create a request passing the orderID in purpose parameter to uniquely Identify the Payment Request. 您可以先在数据库中创建Order,然后创建一个purpose参数中传递orderID 的请求 ,以唯一标识付款请求。 Provide redirect_url and webhook at the time of create a request. 在创建请求时提供redirect_urlwebhook

After any Payment payment_request_id and payment_id is send to the redirect_url provided. 付款后, redirect_url payment_request_idpayment_id发送到提供的redirect_url

Use payment_request_id and payment_id to get the status of the payment , the response will have payment: { ... ,status, ... } use this to update the status in your database. 使用payment_request_idpayment_id获取付款状态,响应将具有payment: { ... ,status, ... }使用它来更新数据库中的状态。

You can use webhook as a fallback if the user accidentally closes the browser window/tab before it reaches the redirect_url. 如果用户在到达redirect_url之前意外关闭了浏览器窗口/选项卡,则可以将webhook用作后备。

For more details, read the documentation 有关更多详细信息,请阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM