Commit 0e45020c authored by peterh-gr's avatar peterh-gr
Browse files

Fixed PayPal

It needed to be modified to permit cookies in the cross-site requests
with fetch and also needed to use the donateProccessorBaseUrl for
calling the endpoints on the donate site.

Also removed some of the pre-react js files that we don't need any more.

Issue #47134
parent bfec50af
......@@ -305,13 +305,14 @@ export function _GivingForm(props) {
recurring = true;
}
const options = {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({'amount': selectedPrice, 'recurring': recurring}),
};
const response = await fetch('/setExpressCheckout', options);
const response = await fetch(`${donateProccessorBaseUrl}/setExpressCheckout`, options);
const response_data = await response.json();
if ('token' in response_data) {
return response_data['token'];
......
......@@ -140,6 +140,7 @@ export function GivingInfoForm(props) {
prepareFieldsData={prepareFieldsData}
createBillingAgreement={createBillingAgreement}
addError={addError}
donateProccessorBaseUrl={donateProccessorBaseUrl}
/>
</React.Fragment>
);
......
import 'babel-polyfill';
import {LoadingDialog} from './loading_dialog';
import {GivingForm} from './giving_form';
import {PaymentController, GiftMatchingController} from './payment_controller'
import React from 'react';
import ReactDOM from 'react-dom';
import {AppContext} from './app_context';
......@@ -45,7 +44,5 @@ if ('reactComponents' in window) {
}
window.tor = {
PaymentController,
GiftMatchingController,
reactCallbacks
};
......@@ -5,7 +5,7 @@ import {NamedError} from './named_error';
import {LoadingDialogReactPages} from './loading_dialog_react_pages';
export function PayPalButton(props) {
const {paymentMethod, amount, perk, frequency, formData, noPerkCheckbox, fitsAndSizes, perkOption, requiredFields, addError, givingFormError, textFields, priceOtherRef, isValidEmail, validateRequiredFieldsAndDonationAmount, preparePerkData, prepareFieldsData, createBillingAgreement} = props;
const {paymentMethod, amount, perk, frequency, formData, noPerkCheckbox, fitsAndSizes, perkOption, requiredFields, addError, givingFormError, textFields, priceOtherRef, isValidEmail, validateRequiredFieldsAndDonationAmount, preparePerkData, prepareFieldsData, createBillingAgreement, donateProccessorBaseUrl} = props;
const PayPalButton = paypal.Buttons.driver('react', {React, ReactDOM});
......@@ -25,6 +25,7 @@ export function PayPalButton(props) {
const onApprove = async (paypalResponse, actions) => {
const options = {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
......@@ -39,7 +40,7 @@ export function PayPalButton(props) {
'token': paypalResponse.orderID,
}),
};
const response = await fetch('/process-paypal', options);
const response = await fetch(`${donateProccessorBaseUrl}/process-paypal`, options);
const response_data = await response.json();
if ('errors' in response_data) {
if (response_data['errors'].length > 0) {
......
This diff is collapsed.
/*
* All of this file is to work around the PayPal first party isolation problem.
* See the README for details.
*/
var $ = require('jquery');
function PaypalProcessor(token, payerId) {
var data = localStorage.getItem('donationData');
if (data === null) {
this.showPaymentErrors(["Couldn't find donationData in local storage."]);
} else {
data = JSON.parse(data);
data['PayerID'] = payerId;
data['token'] = token;
var ajaxSettings = {
contentType: 'application/json; charset=UTF-8',
data: JSON.stringify(data),
dataType: 'json',
type: 'POST',
url: '/process-paypal',
};
$.ajax(ajaxSettings)
.done($.proxy(this.paypalProcessDone, this))
.fail($.proxy(this.paypalProcessFailed, this));
}
}
PaypalProcessor.prototype.paypalProcessDone = function(data, textStatus, jqXHR) {
if (data['errors'].length > 0) {
this.showPaymentErrors(data['errors']);
} else {
localStorage.setItem('donationData', null);
localStorage.setItem('donationDone', true);
window.location.href = "/thank-you";
}
}
PaypalProcessor.prototype.paypalProcessFailed = function(jqXHR, textStatus, errorThrown) {
var errorMessage = "Error processing payment:";
errorMessage = errorMessage + " " + textStatus + ": " + errorThrown;
this.closeLoading();
this.showPaymentErrors([errorMessage]);
}
PaypalProcessor.prototype.showPaymentErrors = function(errors) {
$('.errors-area').show();
$('.title').html("Errors processing donation");
var errorsContainer = $('.errors');
$.each(errors, function(index, error) {
var message = '';
if (typeof error === 'string' || error instanceof String) {
message = error;
}
else if ("message" in error) {
message = error['message'];
}
errorsContainer.append('<li>' + message + '</li>');
});
}
module.exports = PaypalProcessor;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment