Skip to content

Commit

Permalink
WIP: Styles & Sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Jan 3, 2025
1 parent b97f3e7 commit 72d1209
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 32 deletions.
3 changes: 3 additions & 0 deletions out/src/css/paypal.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
max-width: 250px; }
.paypal-button-wrapper.small {
max-width: 200px; }

.paypal-button-container {
margin-left: auto; }
2 changes: 1 addition & 1 deletion out/src/css/paypal.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion out/src/js/paypal-frontend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions resources/build/js/paypal-frontend-googlepay.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,14 @@ window.OxidPayPalGooglePay = {
body: JSON.stringify(paymentData),
}).then((res) => res.json());

const hateoasLinks = new OxidPayPalHateoasLinks();
const approveLink = hateoasLinks.getApproveLink(links);

if (approveLink) {
window.location.href = approveLink;
if (status === "CREATED") {
/* Capture the Order */
this.confirmOrder(orderId, paymentData);
return {transactionState: "SUCCESS"};
} else if (status === "APPROVED") {
/* Capture the Order */
this.captureOrder(orderId);
return {transactionState: "SUCCESS"};
} else if (status === "PAYER_ACTION_REQUIRED") {
console.log("==== Confirm Payment Completed Payer Action Required =====");
this.googlePayUserActionRequired(orderId);
} else {
console.error("Payment was not approved");
return {transactionState: "ERROR"};
Expand All @@ -179,12 +175,32 @@ window.OxidPayPalGooglePay = {
};
}
},
confirmOrder: async function (orderId, paymentData) {
const confirmOrderResponse = await paypal.Googlepay().confirmOrder({
orderId: orderId,
paymentMethodData: paymentData.paymentMethodData
});

const hateoasLinks = new OxidPayPalHateoasLinks();
const payerActionLink = hateoasLinks.getPayerActionLink(confirmOrderResponse.links);

if (confirmOrderResponse.status === "PAYER_ACTION_REQUIRED") {
console.log("==== Confirm Payment Completed Payer Action Required =====");
this.googlePayUserActionRequired(orderId);
} else {
if (this.isSandbox) {
console.log("==== confirmOrder: Not Approved =====");
}
}
},

googlePayUserActionRequired: function (orderId) {
paypal
.Googlepay()
.initiatePayerAction({ orderId: orderId })
.then(async () => {
console.log("===== Payer Action Completed =====");
await this.captureOrder(orderId);
await this.createOxidOrder(orderId);
});
},
Expand Down
28 changes: 24 additions & 4 deletions resources/build/js/paypal-frontend-hateoaslinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,36 @@
*/

/**
* Process an array of links.
* Process an array of links and return the aprove-link
* @param {Link[]} links - An array of link objects.
*
* @returns {string|null}
*/
OxidPayPalHateoasLinks.prototype.getApproveLink = function (links) {
const approveHateoasLink = links.find(link => link.rel === 'approve');
return this.getLinkByKeyword(links, 'approve');
};

/**
* Process an array of links and return the payer-action-link
* @param {Link[]} links - An array of link objects.
*
* @returns {string|null}
*/
OxidPayPalHateoasLinks.prototype.getPayerActionLink = function (links) {
return this.getLinkByKeyword(links, 'payer-action');
};

/**
* Process an array of links.
* @param {Link[]} links - An array of link objects.
*
* @returns {string|null}
*/
OxidPayPalHateoasLinks.prototype.getLinkByKeyword = function (links, keyword) {
const hateoasLink = links.find(link => link.rel === keyword);

if (approveHateoasLink) {
return approveHateoasLink.href;
if (hateoasLink) {
return hateoasLink.href;
}

return null;
Expand Down
3 changes: 3 additions & 0 deletions resources/build/scss/paypal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
max-width: 200px;
}
}
.paypal-button-right {
margin-left: auto;
}
8 changes: 4 additions & 4 deletions resources/grunt/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports = {
style: 'nested'
},
files: {
"../out/src/css/bootstrap.css": "node_modules/bootstrap/scss/bootstrap.scss",
"../out/src/css/paypal.css": "build/scss/paypal.scss",
"../out/src/css/paypal-admin.css": "build/scss/paypal-admin.scss",
"../out/src/css/bootstrap.min.css": "node_modules/bootstrap/scss/bootstrap.scss",
"../out/src/css/paypal.min.css": "build/scss/paypal.scss",
"../out/src/css/paypal-admin.min.css": "build/scss/paypal-admin.scss",
}
},

Expand All @@ -22,7 +22,7 @@ module.exports = {
},
files: {
"../out/src/css/bootstrap.css": "node_modules/bootstrap/scss/bootstrap.scss",
"../out/src/css/paypal.css": "build/scss/paypal.scss",
"../out/src/css/paypal.min.css": "build/scss/paypal.scss",
"../out/src/css/paypal-admin.css": "build/scss/paypal-admin.scss",
}
}
Expand Down
Loading

0 comments on commit 72d1209

Please sign in to comment.