Commit 527fb83c authored by eileen's avatar eileen

Update to smart buttons

parent 5b65185f
......@@ -315,8 +315,10 @@ class CRM_Core_Payment_OmnipayMultiProcessor extends CRM_Core_Payment_PaymentExt
try {
foreach ($fields as $name => $value) {
$fn = "set{$name}";
if (method_exists($this->gateway, $fn)) {
$this->gateway->$fn($value);
}
}
if (\Civi::settings()->get('omnipay_test_mode')) {
$this->_is_test = TRUE;
}
......@@ -356,13 +358,10 @@ class CRM_Core_Payment_OmnipayMultiProcessor extends CRM_Core_Payment_PaymentExt
'id' => $this->_paymentProcessor['payment_processor_type_id'],
'return' => $labelFields)
);
$clientSideCredentials = $this->getProcessorTypeMetadata('client_side_credentials');
foreach ($labelFields as $field => $label) {
if (!isset($clientSideCredentials[$field])) {
$result[$this->camelFieldName($processorFields[$label])] = $this->_paymentProcessor[$field];
}
}
return $result;
}
......
// @see https://developer.paypal.com/docs/checkout/integrate/
(function($) {
var form = $('#billing-payment-block').closest('form');
var qfKey = $('[name=qfKey]', form).val();
// https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/upgrade-integration/
// https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/add-paypal-button/
var formID = CRM.$('#billing-payment-block').closest('form').attr('id');
var qfKey = CRM.$('#' + formID + ' [name=qfKey]').val();
function renderPaypal() {
paypal.Buttons({
createBillingAgreement: function (data, actions) {
renderPaypal = function() {
paypal.Button.render({
env: (CRM.vars.omnipay.is_test ? 'sandbox' : 'production'),
style: {layout: 'vertical', 'size': 'responsive'},
funding: {disallowed: [paypal.FUNDING.CREDIT]},
payment: function (data, actions) {
var frequencyInterval = CRM.$('#frequency_interval').val() ? CRM.$('#frequency_interval').val() : 1;
var frequencyUnit = CRM.$('#frequency_unit').val() ? CRM.$('#frequency_interval').val() : CRM.vars.omnipay.frequency_unit;
return new paypal.Promise(function (resolve, reject) {
var frequencyInterval = $('#frequency_interval').val() || 1;
var frequencyUnit = $('#frequency_unit').val() ? $('#frequency_interval').val() : CRM.vars.omnipay.frequency_unit;
var paymentAmount = calculateTotalFee();
var isRecur = CRM.$('#is_recur').is(":checked");
var isRecur = $('#is_recur').is(":checked");
var recurText = isRecur ? ' recurring' : '';
return new Promise(function (resolve, reject) {
CRM.api3('PaymentProcessor', 'preapprove', {
'payment_processor_id': CRM.vars.omnipay.paymentProcessorId,
'amount': paymentAmount,
'currencyID' : CRM.vars.omnipay.currency,
'qf_key': qfKey,
'is_recur' : isRecur,
'installments' : CRM.$('#installments').val(),
'installments' : $('#installments').val(),
'frequency_unit' : frequencyUnit,
'frequency_interval' : frequencyInterval,
'description' : CRM.vars.omnipay.title + ' ' + CRM.formatMoney(paymentAmount) + recurText
'description' : CRM.vars.omnipay.title + ' ' + CRM.formatMoney(paymentAmount) + recurText,
}
).done(function (result) {
).then(function (result) {
if (result['is_error'] === 1) {
reject(result['error_message']);
}
......@@ -44,7 +40,7 @@ renderPaypal = function() {
});
},
onAuthorize: function (data, actions) {
onApprove: function (data, actions) {
var isRecur = 1;
var paymentToken = data['billingToken'];
if (!paymentToken) {
......@@ -56,7 +52,7 @@ renderPaypal = function() {
document.getElementById('crm-submit-buttons').style.display = 'block';
document.getElementById('PayerID').value = data['payerID'];
document.getElementById('payment_token').value = paymentToken;
document.getElementById(formID).submit();
form.submit();
},
onError: function(err) {
......@@ -64,17 +60,12 @@ renderPaypal = function() {
alert('Site is not correctly configured to process payments');
}
}, '#paypal-button-container');
};
if (typeof paypal === "undefined") {
CRM.$.getScript('https://www.paypalobjects.com/api/checkout.js', function() {
renderPaypal();
});
}
else {
renderPaypal();
}
})
.render('#paypal-button-container');
}
var paypalScriptURL = 'https://www.paypal.com/sdk/js?client-id=' + CRM.vars.omnipay.client_id + '&currency=' + CRM.vars.omnipay.currency + '&commit=false&vault=true';
CRM.loadScript(paypalScriptURL, false)
.done(renderPaypal);
})(CRM.$);
......@@ -64,7 +64,12 @@ return array(
'suppress_submit_button' => 1,
'supports_preapproval' => 1,
'payment_fields' => ['payment_token', 'PayerID', 'post_authorize'],
'pass_through_fields' => ['referrerCode' => 'CiviCRM_SP'],
'pass_through_fields' => [
'referrerCode' => 'CiviCRM_SP',
'returnUrl' => 'https://www.paypal.com/checkoutnow/error',
'cancel_url' => 'https://www.paypal.com/checkoutnow/error',
],
'client_side_credentials' => ['user_name' => 'client_id'],
'payment_fields_metadata' => [
'PayerID' => [
'name' => 'PayerID',
......
......@@ -68,7 +68,7 @@ class api_PreApproveTest extends \PHPUnit_Framework_TestCase implements Headless
'version' => 3,
'email' => 'blah@example.org',
])['values'][0];
$this->assertEquals('PAY-79M30569TN7125128LQGYFLI', $preApproval['token']);
$this->assertEquals('EC-9T988732661526452', $preApproval['token']);
$outbound = $this->getRequestBodies();
......
......@@ -61,7 +61,11 @@ class RestAuthorizeResponse extends RestResponse implements RedirectResponseInte
// The transaction reference for a paypal purchase request or for a
// paypal create subscription request ends up in the execute URL
// in the links section of the response.
$completeUrl = $this->getCompleteUrl();
// this has been HACKED. Paypal changed it's product offering & introduced
// smart buttons instead of checkout.js and it needs something different returned.
// notes here https://github.com/thephpleague/omnipay-paypal/issues/228 but I couldn't see a
// good answer here so I just hacked.
$completeUrl = $this->getRedirectUrl();
if (empty($completeUrl)) {
return parent::getTransactionReference();
}
......@@ -70,6 +74,8 @@ class RestAuthorizeResponse extends RestResponse implements RedirectResponseInte
// The last element of the URL should be "execute"
$execute = end($urlParts);
// part of hack above.
return (str_replace('webscr?cmd=_express-checkout&token=', '', $execute));
if (!in_array($execute, array('execute', 'agreement-execute'))) {
return parent::getTransactionReference();
}
......
Markdown is supported
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