Skip to content

Commit

Permalink
fix order payment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Barbey committed Oct 29, 2024
1 parent 433017a commit 5babaf6
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 14 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions templates/frontOffice/default/paypal/cart-bottom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form id="paypal-express-checkout" method="post" action="{url path='/module/paypal/express/checkout'}" class="pull-right"></form>
<script>
window.paypalCheckoutReady = function() {
paypal.checkout.setup('{$paypal_merchantid}', {
environment: '{$paypal_mode}',
container: 'paypal-express-checkout',
locale: '{lang attr="locale"}'
});
};
</script>
<script src="//www.paypalobjects.com/api/checkout.js" async></script>
85 changes: 85 additions & 0 deletions templates/frontOffice/default/paypal/form/extra-credit-card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<fieldset class="col-xs-11 col-xs-offset-1">
<input type="radio" id="{$label_attr.for}{$choice->label}" class="paypal-method" name="{$name}" data-content="#content-paypal-credit-card" value="{$choice->label}" {if $value == $choice->label}checked{/if}/>
<label class="control-label" for="{$label_attr.for}{$choice->label}"><strong>{intl l=$choice->label d="paypal.fo.default"}</strong>&nbsp;:<br />{if $required} <span class="required">*</span>{/if}</label>
<img src="{image file='assets/cards-logo.jpg' source="PayPal"}" border="0" alt="CB / VISA / Mastercard" />

<div id="content-paypal-credit-card" class="hidden">
{form_field field='paypal_credit_card_type.card_type'}
<div class="form-group row{if $error} has-error{/if}">
<label class="control-label col-sm-3" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input col-sm-5">

<select name="{$name}" id="{$label_attr.for}">
{foreach from=$choices item=type}
<option value="{$type->value}">{$type->label}</option>
{/foreach}
</select>
{if $error }
<span class="help-block">{$message}</span>
{assign var="error_focus" value="true"}
{/if}
</div>
</div>
{/form_field}

{form_field field='paypal_credit_card_type.card_number'}
<div class="form-group row{if $error} has-error{/if}">
<label class="control-label col-sm-3" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input col-sm-5">
<input type="text" name="{$name}" id="{$label_attr.for}" value="" />
</div>
{if $error }
<span class="help-block">{$message}</span>
{assign var="error_focus" value="true"}
{/if}
</div>
{/form_field}

{form_field field='paypal_credit_card_type.card_expire_month'}
<div class="form-group row{if $error} has-error{/if}">
<label class="control-label col-sm-3" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input col-sm-5">
<select name="{$name}" id="{$label_attr.for}">
{foreach from=$choices item=type}
<option value="{$type->value}">{$type->label}</option>
{/foreach}
</select>
{if $error }
<span class="help-block">{$message}</span>
{assign var="error_focus" value="true"}
{/if}
</div>
</div>
{/form_field}

{form_field field='paypal_credit_card_type.card_expire_year'}
<div class="form-group row{if $error} has-error{/if}">
<label class="control-label col-sm-3" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input col-sm-5">
<select name="{$name}" id="{$label_attr.for}">
{foreach from=$choices item=type}
<option value="{$type->value}">{$type->label}</option>
{/foreach}
</select>
{if $error }
<span class="help-block">{$message}</span>
{assign var="error_focus" value="true"}
{/if}
</div>
</div>
{/form_field}

{form_field field='paypal_credit_card_type.card_cvv'}
<div class="form-group row{if $error} has-error{/if}">
<label class="control-label col-sm-3" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input col-sm-5">
<input type="text" name="{$name}" id="{$label_attr.for}" value="" />
{if $error }
<span class="help-block">{$message}</span>
{assign var="error_focus" value="true"}
{/if}
</div>
</div>
{/form_field}
</div>
</fieldset>
17 changes: 17 additions & 0 deletions templates/frontOffice/default/paypal/form/extra-paypal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<fieldset class="col-xs-11 col-xs-offset-1">
{if $method_paypal_with_in_context}
<input type="radio" id="{$label_attr.for}{$choice->label}-express" class="paypal-method paypal-express-method" name="{$name}" value="{$choice->label}" {if $value == $choice->label}checked{/if}/>
<label class="control-label" for="{$label_attr.for}{$choice->label}-express">
<strong>{intl l=$choice->label d="paypal.fo.default"}</strong>&nbsp;:
<img src="{image file='assets/paypal-logo.png' source="PayPal"}" border="0" alt="PayPal account" />
</label>
{else}
<input type="radio" id="{$label_attr.for}{$choice->label}" class="paypal-method" name="{$name}" value="{$choice->label}" {if $value == $choice->label}checked{/if}/>
<label class="control-label" for="{$label_attr.for}{$choice->label}">
<strong>{intl l=$choice->label d="paypal.fo.default"}</strong>&nbsp;:
<img src="{image file='assets/paypal-logo.png' source="PayPal"}" border="0" alt="PayPal account" />
</label>
{/if}


</fieldset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{assign var="methodName" value=$name}
{form_field field='paypal_planified_payment'}
{if count($choices) > 0}
<fieldset class="col-xs-11 col-xs-offset-1">
<input type="radio" id="{$label_attr.for}{$choice->label}" class="paypal-method" name="{$methodName}" data-content="#content-paypal-planified-payment" value="{$choice->label}" {if $value == $choice->label}checked{/if}/>
<label class="control-label" for="{$label_attr.for}{$choice->label}"><strong>{intl l=$choice->label d="paypal.fo.default"}</strong>&nbsp;:<br />{if $required} <span class="required">*</span>{/if}</label>
<div id="content-paypal-planified-payment" class="hidden">
{foreach $choices as $choice}
{assign var="planifiedPayment" value=$choice->data}
<div class="form-group row{if $error} has-error{/if}">
<div class="control-input col-sm-5">
<input type="radio" id="{$label_attr.for}{$planifiedPayment->getId()}" name="{$name}" value="{$planifiedPayment->getId()}" {if $value == $planifiedPayment->getId()}checked{/if}/>
<label class="control-label" for="{$label_attr.for}{$planifiedPayment->getId()}"><strong>{$planifiedPayment->getTitle()}</strong>&nbsp;:<br />{if $required} <span class="required">*</span>{/if}</label>
<div class="row">
<div class="col-md-12">
{$planifiedPayment->getDescription()}
</div>
</div>
</div>
</div>
{/foreach}
</div>
</fieldset>
{/if}
{/form_field}

16 changes: 16 additions & 0 deletions templates/frontOffice/default/paypal/login-bottom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<article>
<span id='lippButton'></span>
<script src='https://www.paypalobjects.com/js/external/api.js'></script>
<script>
paypal.use( ['login'], function (login) {
login.render ({
"appid":'{$paypal_appid}',
"authend":'{$paypal_authend}',
"scopes":"profile email address phone https://uri.paypal.com/services/paypalattributes",
"containerid":"lippButton",
"locale":"fr-fr",
"returnurl":'{url path="/module/paypal/login/ok"}'
});
});
</script>
</article>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
$('#form-cart-delivery button:submit').each(function() {
if (!$(this).hasClass('paypal')) {
$(this).addClass('hidden');
}
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<button class="btn btn-primary pull-right paypal" type="submit">
<i class="fa fa-chevron-right"></i>
{intl l='Finish payment with PayPal' d='paypal.fo.default'}
</button>
11 changes: 11 additions & 0 deletions templates/frontOffice/default/paypal/order-invoice-bottom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form id="paypal-express-checkout" method="post" action="{url path='/module/paypal/invoice/express/checkout'}" class="hidden"></form>
<script>
window.paypalCheckoutReady = function() {
paypal.checkout.setup('{$paypal_merchantid}', {
environment: '{$paypal_mode}',
container: 'paypal-express-checkout',
locale: '{lang attr="locale"}'
});
};
</script>
<script src="//www.paypalobjects.com/api/checkout.js" async></script>
58 changes: 58 additions & 0 deletions templates/frontOffice/default/paypal/order-invoice-js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script type="text/javascript">
var payPalModuleId = '{$module_id}';

(function ($) {

{literal}
$(document).ready(function () {
var $payPal = $('#payment_' + payPalModuleId)
, $payPalMethod = $('input:radio[class=paypal-method]')
, hasSelection = false
;

if ($payPal.prop('checked')) {
$('#paypal-methods').removeClass('hidden');
}

$('#payment-method input:radio').on('change', function() {
if ($(this).attr('name') === 'thelia_order_payment[payment-module]') {
if ($(this).attr('id') === $payPal.attr('id')) {
$('#paypal-methods').removeClass('hidden');
} else {
$('#paypal-methods').addClass('hidden');
}
}
});

$payPalMethod.on('change', function() {
//$payPalMethod.prop('checked', true);
$($(this).data('content')).removeClass('hidden');

$('input:radio').each(function(){
if ($(this).attr('name') == "thelia_order_payment[paypal_method]" && $(this).prop('checked')) {
hasSelection = true;
$($(this).data('content')).removeClass('hidden');
} else {
$($(this).data('content')).addClass('hidden');
}
});
});

$('input:radio').each(function(){

if ($(this).attr('name') == "thelia_order_payment[paypal_method]" && $(this).prop('checked')) {
hasSelection = true;
$($(this).data('content')).removeClass('hidden');
}
});

$('.paypal-express-method').on('click', function(){
$('#paypal-express-checkout button').each(function(){
$(this).trigger('click');
});
});

});
{/literal}
})(jQuery);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{form name="thelia.order.payment"}
<div id="paypal-methods" class="row hidden">
<hr>
{form_field field='paypal_method'}
{foreach from=$choices item=choice}

{if $choice->label == 'paypal' && {module_config key="method_paypal" module="PayPal" locale="en_US"} == 1}
{include file="paypal/form/extra-paypal.html"}
{/if}

{if $choice->label == 'credit_card' && {module_config key="method_credit_card" module="PayPal" locale="en_US"} == 1}
{include file="paypal/form/extra-credit-card.html"}
{/if}

{if $choice->label == 'planified_payment' && {module_config key="method_planified_payment" module="PayPal" locale="en_US"} == 1}
{include file="paypal/form/extra-planified-payment.html"}
{/if}
{/foreach}
{/form_field}
</div>
{/form}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{loop type="paypal_order" name="paypal_order" id=$placed_order_id limit=1}
{if $paypal_order->getPlanifiedCycle() > 0}
<strong>{intl l="Planified payment" d="paypal.fo.default"}</strong>&nbsp;:&nbsp;
{intl l="Payment in %x times every %frequency_interval %frequency" x=$paypal_order->getPlanifiedCycle() frequency_interval=$paypal_order->getPlanifiedFrequencyInterval() frequency="{intl l=$paypal_order->getPlanifiedFrequency() d="paypal.fo.default"}" d="paypal.fo.default"}
{/if}
{/loop}
26 changes: 12 additions & 14 deletions templates/frontOffice/default/paypal/paypal-payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ <h1 class="text-2xl">{intl l="PayPal - Sélection de paiement"}</h1>
</script>
{else}
<script>
const orderId = {$order_id};

async function createPaypalOrder(orderId)
{
try {
Expand Down Expand Up @@ -145,21 +147,17 @@ <h1 class="text-2xl">{intl l="PayPal - Sélection de paiement"}</h1>
}
}

const orderId = {$order_id};

createPaypalOrder(orderId).then(order => {
if (order) {
console.log('Order:', order);-
paypal.Buttons({
onApprove: function (data, actions) {
window.location.href = `/order/placed/{$order_id}`;
}
}).render('#paypal-button-container'); // Renders the PayPal button

} else {
console.error('Failed to create PayPal order');
paypal.Buttons({
createOrder: function(data, actions) {
return createPaypalOrder(orderId)
},
onApprove: function (data, actions) {
console.log('test Paypal')
console.log(data.orderID)
window.location.href = `/order/placed/{$order_id}`;
}
});
}).render('#paypal-button-container');

</script>
{/if}
{/block}
Expand Down

0 comments on commit 5babaf6

Please sign in to comment.