// Copyright (c) 2022, JINGROW
// For license information, please see license.txt

jingrow.ui.form.on('Stripe Micro Charge Record', {
	refresh: function (frm) {
		if (!frm.pg.has_been_refunded) {
			const btn = frm.add_custom_button('Refund', () => {
				frm
					.call({
						pg: frm.pg,
						method: 'refund',
						btn,
					})
					.then((r) => {
						if (r.message) {
							jingrow.msgprint(`Refunded Successfully.`);
						}
						frm.refresh();
					});
			});
		}

		frm.add_web_link(
			`https://dashboard.stripe.com/payments/${frm.pg.stripe_payment_intent_id}`,
			'View in Stripe Dashboard',
		);
	},
});
