Created
August 15, 2017 01:03
-
-
Save mastfissh/f8f4a5d753585f18198bea800e318682 to your computer and use it in GitHub Desktop.
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
if (refund_method == 'Back To Original') { | |
payments.each do |payment| | |
paymentRefunder = new paymentRefunder(payment, cookie, currency) | |
paymentRefunder.attemptRefund(refundAmounts[payment.type]) | |
end | |
return; | |
} | |
if (refund_method == 'Le Credits') { | |
refundableAmount = 0; | |
payments.each do |payment| | |
refundableAmount = refundableAmount + parseFloat(payment.amount); | |
end | |
if (refundableAmount > 0) { | |
let creditsDetails = { | |
"amount": refundableAmount, | |
"currency": payments.result[0].currency, | |
"fk_member": order.fk_customer_id, | |
"credit_type": "Refund", | |
"comments": `Refund for order ${requestData.id_orders}` | |
} | |
await paymentService.addCredits(creditsDetails) | |
} | |
return | |
} | |
paymentRefunder | |
if (payment_type == "le_credit") { | |
this.attemptRefund = function(amount){ | |
await attemptRefundStripe(payments.result[i], cookie, refund_method, refundAmounts[payment_type], payments.result[i].currency); | |
} | |
} | |
if (refund_method == 'Back To Original') { | |
for (let i = 0; i < payments.result.length; i++) { | |
let payment_type = payments.result[i].type; | |
if (payment_type == "le_credit") { | |
if (refundAmounts && refundAmounts[payment_type]) { | |
await attemptRefundCredit(payments.result[i], cookie, refund_method, refundAmounts[payment_type]); | |
} else { | |
await attemptRefundCredit(payments.result[i], cookie, refund_method); | |
} | |
} else if (payment_type == "stripe") { | |
if (partialRefund == false) { | |
await attemptRefundStripe(payments.result[i], cookie, refund_method); | |
} else if (partialRefund == true && refundAmounts[payment_type] != 0) { | |
await attemptRefundStripe(payments.result[i], cookie, refund_method, refundAmounts[payment_type], payments.result[i].currency); | |
} | |
} else if (payment_type == "paypal_express") { | |
if (partialRefund == false) { | |
await attemptRefundPaypal(payments.result[i], cookie, refund_method); | |
} | |
} | |
} | |
} else if (refund_method == 'Le Credits') { | |
for (let i = 0; i < payments.result.length; i++) { | |
let payment_type = payments.result[i].type; | |
if (payment_type == "le_credit") { | |
creditsAmount = parseFloat(payments.result[i].amount); | |
await attemptRefundCredit(payments.result[i], cookie, refund_method, refundAmounts[payment_type], payments.result[i].currency); | |
} | |
refundableAmount = refundableAmount + parseFloat(payments.result[i].amount); | |
} | |
// the remainder amount(if any) is added with separate LE credits | |
refundableAmount = parseFloat(refundableAmount - creditsAmount); | |
if (refundableAmount > 0) { | |
let creditsDetails = { | |
"amount": refundableAmount, | |
"currency": payments.result[0].currency, | |
"fk_member": order.fk_customer_id, | |
"credit_type": "Refund", | |
"comments": `Refund for order ${requestData.id_orders}` | |
} | |
await paymentService.addCredits(creditsDetails) | |
} | |
} else if (refund_method == 'Manual') { | |
// TODO: implement this | |
console.log(`Refunding order ${requestData.id_orders} manually`) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment