fix billing details + card data processing

remove saving billing address details to database in the first place
before sending to recurly. Now the backend handles address data saving
after success response from recurly.
This commit is contained in:
Nuwan 2025-08-15 18:31:03 +05:30
parent 3bba9ec619
commit 25ecab2c65
2 changed files with 67 additions and 21 deletions

View File

@ -196,21 +196,70 @@ const JKPaymentMethod = () => {
});
};
const onSubmit = async (data) => {
// const onSubmit = async (data) => {
// //first update billing address
// setSubmitting(true);
// const resp = await updateBillingInfo(data)
// if (!resp.ok) {
// setSubmitting(false);
// const errorData = await resp.json();
// console.error('Error updating billing info:', errorData);
// toast.error(errorData.message || t('payment_method.alerts.billing_update_error'));
// return;
// }
// if (paymentMethod === 'paypal') {
// handoverToPaypal();
// return;
// } else {
// if (!elementsRef.current) {
// console.error('Recurly elementsRef.current is not ready');
// setSubmitting(false);
// return;
// }
// if (!formRef.current) {
// console.error('formRef.current is not ready');
// setSubmitting(false);
// return;
// }
// // if (!isCardValid) {
// // console.error('Card is not valid');
// // toast.error(t('payment_method.validations.card.invalid'));
// // setSubmitting(false);
// // return;
// // }
// window.recurly.token(elementsRef.current, formRef.current, (err, token) => {
// if (err) {
// console.error('Recurly token error:', err);
// toast.error(err.message || t('payment_method.alerts.card_processing_error'));
// setSubmitting(false);
// } else {
// console.log('Recurly token:', token.id);
// // send token.id to backend
// handleUpdatePayment(token);
// }
// });
// }
// };
const onSubmit = async (data) => {
//first update billing address
setSubmitting(true);
const resp = await updateBillingInfo(data)
if (!resp.ok) {
setSubmitting(false);
const errorData = await resp.json();
console.error('Error updating billing info:', errorData);
toast.error(errorData.message || t('payment_method.alerts.billing_update_error'));
return;
}
// const resp = await updateBillingInfo(data)
// if (!resp.ok) {
// setSubmitting(false);
// const errorData = await resp.json();
// console.error('Error updating billing info:', errorData);
// toast.error(errorData.message || t('payment_method.alerts.billing_update_error'));
// return;
// }
if (paymentMethod === 'paypal') {
handoverToPaypal();
return;
} else {
} else { // Credit Card payment method
if (!elementsRef.current) {
console.error('Recurly elementsRef.current is not ready');
@ -223,17 +272,10 @@ const JKPaymentMethod = () => {
return;
}
// if (!isCardValid) {
// console.error('Card is not valid');
// toast.error(t('payment_method.validations.card.invalid'));
// setSubmitting(false);
// return;
// }
window.recurly.token(elementsRef.current, formRef.current, (err, token) => {
if (err) {
console.error('Recurly token error:', err);
toast.error(err.message || t('payment_method.alerts.card_processing_error'));
toast.error(t('payment_method.alerts.card_processing_error'));
setSubmitting(false);
} else {
console.log('Recurly token:', token.id);
@ -265,7 +307,7 @@ const JKPaymentMethod = () => {
<strong>{t('payment_method.help_text_no_card')}</strong>
</span>
)}
{t('payment_method.help_text')}
&nbsp;{t('payment_method.help_text')}
</div>
<form onSubmit={handleSubmit(onSubmit)} ref={formRef}>
@ -480,7 +522,7 @@ const JKPaymentMethod = () => {
<Button
color="primary"
type="submit"
disabled={submitting || !billingDataLoaded }
disabled={ submitting }
className="mt-3"
>
{submitting ? t('payment_method.submitting') : t('payment_method.save_payment_info')}

View File

@ -1,7 +1,11 @@
object @profile
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :location, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :follower_count, :following_count, :recording_count, :session_count, :biography, :favorite_count, :audio_latency, :upcoming_session_count, :age, :website, :skill_level, :concert_count, :studio_session_count, :virtual_band, :virtual_band_commitment, :traditional_band, :traditional_band_commitment, :traditional_band_touring, :paid_sessions, :paid_sessions_hourly_rate,
:paid_sessions_daily_rate, :free_sessions, :cowriting, :cowriting_purpose, :subscribe_email, :is_a_teacher, :is_a_student, :last_active_timestamp, :v2_photo_url, :v2_photo_uploaded
:paid_sessions_daily_rate, :free_sessions, :cowriting, :cowriting_purpose, :subscribe_email, :is_a_teacher, :is_a_student, :last_active_timestamp, :v2_photo_url, :v2_photo_uploaded, :has_stored_credit_card?
node :has_recurly_account do |user|
user.recurly_code == user.id
end
child :online_presences => :online_presences do
attributes :id, :service_type, :username