Arsalan
Arsalan2w ago

Does "requestPayment" method have promise? and return orderId,paymentKey & amount?

Hi Support & @Ayaan! I need to know that, can i use ".then" & ".catch" with requestPayment method? Please suggest! Thanks
26 Replies
토스페이먼츠 BOT
⏳ 잠시만 기다려주세요! 곧 답변드리겠습니다
오류 문의일 경우 아래 정보를 미리 전달해주시면, 빠른 답변에 도움이 됩니다.
- 주문번호(orderId) : - 문의 내용 :
(img를 함께 첨부해주시면 도움이됩니다)
* 계약관련 내용은 1544-7772로 문의주세요. * 주말/공휴일에는 답변이 늦을 수 있어요.
Ayaan
Ayaan2w ago
Hi @Arsalan! Absolutely! You can use .then() and .catch() with requestPayment method, as method returns Promise. Just handle the method like when you handle Promise.
Arsalan
ArsalanOP2w ago
Thank you @Ayaan 👍 Yes i have verified & both worked with v1. Does these also works with v2?
Ayaan
Ayaan2w ago
Not every methods are available on v2, because some of them deprecated or not implemented yet. If you verified that works on v1, just keep use v1. We won't deprecate v1
Arsalan
ArsalanOP2w ago
Appreciate! but i've instructed to use latest version. All i need right now is, I want to catch these parameters via .then() & save these parameters to relative order & doesn't want to redirect to Success OR Fail URLs. Can i do that with this library? https://js.tosspayments.com/v2/standard
{
"paymentKey": "tviva202411131429345nE24",
"orderId": "rfMtsUySPv5CBPftWLc_1",
"amount": 15600
}
{
"paymentKey": "tviva202411131429345nE24",
"orderId": "rfMtsUySPv5CBPftWLc_1",
"amount": 15600
}
Ayaan
Ayaan2w ago
Your needs cannot be performed either v1 or v2. You can do it on PC environment, but it might not working on Mobile env due to browser security limitations (CORS, etc) On PC, if you don't pass successUrl / failUrl to the requestPayment method, you will get the parameters that should passed to successUrl is returned as Promise. Hence, you can access those by .then().
Arsalan
ArsalanOP2w ago
But I've seen that "successUrl" & "failUrl" parameters are optional in official documentation. is it mandatory to pass these parameters?
Ayaan
Ayaan2w ago
However on Mobile env, due to browser limitations, it should be redirected to 3DS page. Hence, you can't receive the parameters as Promise. That's why successUrl and failUrl is mandatory in this case. It is optional, only in PC. Not Mobile.
Arsalan
ArsalanOP2w ago
On PC, if you don't pass successUrl / failUrl to the requestPayment method, you will get the parameters that should passed to successUrl is returned as Promise. Hence, you can access those by .then().
Yes i've verified this & it works for me (using v1)
Ayaan
Ayaan2w ago
Also works in v2, only in PC.
Arsalan
ArsalanOP2w ago
It is optional, only in PC. Not Mobile.
Does this mean mobile browser OR mobile App?
Ayaan
Ayaan2w ago
Because of this, on both versions, v1 and v2, now throws error when successUrl / failUrl is not passed if it is performed on mobile env. Both.
Arsalan
ArsalanOP2w ago
Hmmm... 🤔
Ayaan
Ayaan2w ago
Try not to pass successUrl and failUrl in Mobile. It will throw the error, if I remember correctly... Please kindly understand that this behaviour is from browser's security limitations. It is not Toss Payments' responsibility.
Arsalan
ArsalanOP2w ago
Understood! Let me follow above & try! Thank you for this help & detail briefing 🫡
Ayaan
Ayaan2w ago
If you want more technical details for this behaviour, The payment process is going through tosspayments.com to Card company's 3DS page (different domain). It causes CORS problem, and finally loses the session. Thanks 🙏 Personally I highly recommend that use successUrl and failUrl on both device types. This really will make your life easier for implementing. Please follow up if you succeed or failed. @Arsalan
Arsalan
ArsalanOP2w ago
@Ayaan Appreciate 🙏 Can i use webhook to deal with this? in case i don't get response from .then()
Ayaan
Ayaan2w ago
No, because you should call the "confirm" API to make money out of customers. After that, you can receive the webhook. so if you don't get response from .then() or successUrl, the transaction would not be happened.
Arsalan
ArsalanOP2w ago
Acknowledged!
Ayaan
Ayaan2w ago
@Arsalan Could you let me know what your needs exactly is? Why you don't want to use successUrl? We will find out which way of implementing is right for you
Arsalan
ArsalanOP2w ago
Hi @Ayaan, I've used below parameters with succesUrl & failUrl. but i got this error ""successUrl" 또는 "failUrl"을 넘긴 경우 Promise 방식을 지원하지 않습니다." why? I am testing these parameters on desktop browser! Please suggest! Thanks
tossPayments.requestPayment("CARD", {
amount: wc_toss_params.cartAmount,
orderId: wc_toss_params.orderId,
orderName: wc_toss_params.cartItemsDesc,
customerName: wc_toss_params.customerName,
_skipAuth: 'FORCE_FAIL',
successUrl: wc_add_to_cart_params.checkoutUrl,
failUrl: wc_add_to_cart_params.checkoutUrl,
customerEmail: document.getElementById('billing_email').value,
})
tossPayments.requestPayment("CARD", {
amount: wc_toss_params.cartAmount,
orderId: wc_toss_params.orderId,
orderName: wc_toss_params.cartItemsDesc,
customerName: wc_toss_params.customerName,
_skipAuth: 'FORCE_FAIL',
successUrl: wc_add_to_cart_params.checkoutUrl,
failUrl: wc_add_to_cart_params.checkoutUrl,
customerEmail: document.getElementById('billing_email').value,
})
Ayaan
Ayaan2w ago
@Arsalan You only can use Promise (.then()) when you didn't sent the success/failUrl
Arsalan
ArsalanOP2w ago
Hi @Ayaan, I've almost done & finished. Thanks for your help! Its working fine at my localhost. when i deploy it on my testing server. the toss payment library is not loading there. https://js.tosspayments.com/v1/payment please suggest!
Ayaan
Ayaan7d ago
@Arsalan Hi there, sorry for late reply Could you please check Logs on Chrome Devtools and screenshot it for us?
Arsalan
ArsalanOP3d ago
Hi @Ayaan, I am also sorry for delayed response. I just checked it right now! I had resolved it & now library loads fine on all environments. Also I've finished the integration. 🤝 Thanks alot for your help! we may consider this thread as closed!
Ayaan
Ayaan3d ago
Thank you so much for follow up and I am very appreciated! This ticket will be changed to closed, and please create a new thread if there are any further question came out!!