Skip to content

Commit

Permalink
refactor(app): remove amz code from src/mixins and src/libs
Browse files Browse the repository at this point in the history
files affected: src/mixins/payments.js and src/libs/payments.json
  • Loading branch information
CuriousMagpie committed Dec 2, 2024
1 parent 7d0ce8a commit 93a3693
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 87 deletions.
19 changes: 2 additions & 17 deletions website/client/src/libs/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@ import getStore from '@/store';
export function setup () { // eslint-disable-line import/prefer-default-export
const store = getStore();

Check failure on line 4 in website/client/src/libs/payments.js

View workflow job for this annotation

GitHub Actions / production-build (21.x)

'store' is assigned a value but never used

// // Set Amazon Payments as ready in the store,
// // Added here to make sure the listener is registered before the script can be executed
window.onAmazonLoginReady = () => {
store.state.isAmazonReady = true;
window.amazon.Login.setClientId(process.env.AMAZON_PAYMENTS_CLIENT_ID);
};

// Load the scripts

// Amazon Payments
const amazonScript = document.createElement('script');
let firstScript = document.getElementsByTagName('script')[0];
amazonScript.type = 'text/javascript';
amazonScript.async = true;
amazonScript.src = `https://static-na.payments-amazon.com/OffAmazonPayments/us/${(process.env.AMAZON_PAYMENTS_MODE === 'sandbox' ? 'sandbox/' : '')}js/Widgets.js`;
firstScript.parentNode.insertBefore(amazonScript, firstScript);
// Load the payment scripts

// Stripe
const stripeScript = document.createElement('script');
[firstScript] = document.getElementsByTagName('script');
let firstScript = document.getElementsByTagName('script')[0];

Check failure on line 10 in website/client/src/libs/payments.js

View workflow job for this annotation

GitHub Actions / production-build (21.x)

'firstScript' is never reassigned. Use 'const' instead
stripeScript.async = true;
stripeScript.src = 'https://js.stripe.com/v3/';
firstScript.parentNode.insertBefore(stripeScript, firstScript);
Expand Down
71 changes: 1 addition & 70 deletions website/client/src/mixins/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,76 +263,7 @@ export default {
}
return true;
},
amazonPaymentsInit (data) {
if (data.type !== 'single' && data.type !== 'subscription') return;

if (data.type === 'single') {
this.amazonPayments.gemsBlock = data.gemsBlock;
this.amazonPayments.sku = data.sku;
}

if (data.gift) {
if (data.gift.gems && data.gift.gems.amount && data.gift.gems.amount <= 0) return;
data.gift.uuid = data.giftedTo;
this.amazonPayments.giftReceiver = data.receiverName;
}

if (data.subscription) {
this.amazonPayments.subscription = data.subscription;
this.amazonPayments.coupon = data.coupon;
}

if (data.groupId) {
this.amazonPayments.groupId = data.groupId;
}

if (data.group) { // upgrading a group
this.amazonPayments.group = data.group;
}

if (data.groupToCreate) { // creating a group
this.amazonPayments.groupToCreate = data.groupToCreate;
}

if (data.demographics) { // sending demographics
this.amazonPayments.demographics = data.demographics;
}

this.amazonPayments.gift = data.gift;
this.amazonPayments.type = data.type;
},
amazonOnError (error) {
window.alert(error.getErrorMessage()); // eslint-disable-line no-alert
this.reset();
},
// Make sure the amazon session is reset between different sessions and after each purchase
amazonLogout () {
if (window.amazon && window.amazon.Login && typeof window.amazon.Login.logout === 'function') {
window.amazon.Login.logout();
}
},
reset () {
// @TODO: Ensure we are using all of these
// some vars are set in the payments mixin. We should try to edit in one place
this.amazonLogout();

this.amazonPayments.modal = null;
this.amazonPayments.type = null;
this.amazonPayments.loggedIn = false;

// Gift
this.amazonPayments.gift = null;
this.amazonPayments.giftReceiver = null;

this.amazonPayments.billingAgreementId = null;
this.amazonPayments.orderReferenceId = null;
this.amazonPayments.paymentSelected = false;
this.amazonPayments.recurringConsent = false;
this.amazonPayments.subscription = null;
this.amazonPayments.coupon = null;
this.amazonPayments.groupToCreate = null;
this.amazonPayments.group = null;
},
cancelSubscriptionConfirm (config) {
if (config.canCancel === false) return;
this.$root.$emit('habitica:cancel-subscription-confirm', config);
Expand All @@ -348,7 +279,7 @@ export default {
let paymentMethod = group
? group.purchased.plan.paymentMethod
: this.user.purchased.plan.paymentMethod;
paymentMethod = paymentMethod === 'Amazon Payments' ? 'amazon' : paymentMethod.toLowerCase();
paymentMethod = paymentMethod.toLowerCase();

const queryParams = {
noRedirect: true,
Expand Down

0 comments on commit 93a3693

Please sign in to comment.