PayPal Encrypt cart data - encryption

Im using ExpressIonEngine, and there is some module Simple Commerce, which doesnt provide what I want.
Created everything that I needed, but then I wanted to improve it, so everything in cart should be encrypted, so none can alter DOM or whatever... :)
Here is example array which I'm encrypting, but when I submit form to PayPal Sandbox, Im getting error like: We were unable to decrypt the certificate id.
Array
(
[cmd] => _cart
[business] => info#SomeDomain.com
[cert_id] => *********** // hidden off course
[upload] => 1
[return] => http://SomeDomain.com/shop/thanks/
[cancel_return] => http://SomeDomain.com/shop/
[lc] => EN
[currency_code] => EUR
[custom] => 1
[item_number_1] => 711
[item_name_1] => Some Issue 03
[amount_1] => 5.90
[quantity_1] => 3
[item_number_2] => 708
[item_name_2] => Some Issue 02
[amount_2] => 1.00
[quantity_2] => 5
)
Form is like:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----
MIIIMwYJKoZIhvcNAQcDoIIIJDCCCCACAQAxggEwMIIBLAIBADCBlDCBjjELMAkG
A1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQw
EgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UE
AxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJ
KoZIhvcNAQEBBQAEgYB9MZM/Jb6UbHsStVMBFfO5fz6oTNZ0dGIf2H3h7vfyLdE3
kWuMiN46EUcguses8uDezIbIsEGH/7J4sgJqsqfA5kf3nwmuzETCpGOBgzTK96JK
QwABQPBsh4uwVC0Hbq9jT1KuYF35pmdFRo5ZG6UHzsG4jgSiSJjqdVVW7zyI3DCC
BuUGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIYDLQTJqKWGGAggbAhQqnhMGMbBDw
h5S8t773pBpyeGsOQ7HLcl7l90IZtjlEm2Ke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/ARrKwpPpMK
8/WV9Lf52fz/Kk657eQe5N5+W00Wqpor3bFzP4z6XazxP7bSpNhhOudQx3cKEBlK
LlWYRd867FHu0+vcHr3jri1+VeoUX1f2XxmYNjKHxsDWYBdFbEWN
-----END PKCS7-----">
<input type="submit" value="Checkout With PayPal" />
</form>
Tried 2 way of encrypt.
ExpressionEngine function encrypt_data(). This works well but only for one product and adding directly to PayPal shopping cart. When I pass data from above array to the same encrypt function, PayPal cant decrypt certificate id?!
Tried also function from here but same problem... PayPal cant decrypt certificate_id.
I know that everything works, because native EE function works.
Could any one help me and suggest what to do?
Thanks in advance

http://blog.scrobbld.com/paypal/protecting-your-payments-with-ewp/
Works, just exchange the certificater params.

Related

Symfony DateTime format errors - datatransformation (external datepicker)

I'm working with Symfony 6 and a TempusDomini datepicker.
I have read (amongst many others) the symfony documentation, https://symfony.com/doc/current/reference/forms/types/datetime.html.
Based on the documentation I found I initially implemented the form builder as followed:
->add('TextDateField')
->add('RegistrationDateTime', DateTimeType::class, [
'required' => false,
'widget' => 'single_text',
'format' => 'm/d/Y, h:i a',
'attr' => [
'class' => 'datetimepicker-input',
'data-target' => '#datetimepicker1'
],
'html5' => false,
])
The "TextDateField" is for troubleshooting, see explanation below.
And the actual TWIG file looks like this (for the TextDateField I have a similar datapicker block as the one for RegistrationDateTime):
{{form_start(form)}}
{{form_row(form.username)}}
<div class>
<label for="datetimepicker1Input" class="form-label">Simple picker</label>
<div class="input-group" id="datetimepicker1" data-td-target-input="nearest" data-td-target-toggle="nearest">
<input id="user_creation_form_RegistrationDateTime" name="user_creation_form[RegistrationDateTime]" type="text" class="form-control" data-td-target="#datetimepicker1">
<span class="input-group-text" data-td-target="#datetimepicker1" data-td-toggle="datetimepicker">
<span class="fa-solid fa-calendar"></span>
</span>
</div>
<script type="text/javascript">
const picker = new tempusDominus.TempusDominus(document.getElementById('datetimepicker1'));
</script>
</div>
{{form_row(form.roles)}}
{{form_row(form._token)}}
{{form_row(form.submit)}}
What I notice is that the dates are correctly given from a datepicker to the controller if passed via Text.
Please see this dump where you can see 2 datepicker values as passed to the controller, both for the same dates (6 may 2022)
App\Entity\TUser^ {#361
-id: null
-username: "scdsqd"
-roles: array:2 [
0 => "ROLE_USER"
1 => "ROLE_ADMIN"
]
-TextDateField: "05/06/2022, 12:42 PM"
-RegistrationDateTime: DateTime #1640599500 {#828
date: 2021-12-27 11:05:00.0 Europe/Berlin (+01:00)
}
}
So as you can see the text is passed correctly for the "text" datepicker but using the symfony DateTimeType::class messes it up by giving a seemingly random date.
Using other formats as datetime (for example timestamp) is not possible.
So how can I pass the value correctly to the database?
One possible "solution" is to work with TextType::class but since I want to keep the field RegistrationDateTime in the database as a DateTimeType this is not the best solution either since that would mean I have to transform the data.
Maybe I'm not looking at the right place, but it seems to me as if Symfony is not well adjusted to use external datepickers.
I have found tons of post with people struggling to implement a datepicker...
Is the approach I use correct?
How can I "force" symfony to "understand" the datepicker provided dates?
If the only way is to use TextType in the form-builder, how do I tackle the datatransformations to make sure that via doctrine I save in the datetime format?
Any pointers in the right direction are welcome... I'm getting rather frustrated by it since I've struggled on it an embarrassingly long time now...

In cakephp 3 I got error Unexpected field in POST data

In cakephp 3 I got error Unexpected field in POST data.
Actually that field is not in my table, but I want to use in controller.
The Security Component in CakePHP is not forgiving. If you want to allow a field thru that should not go thru the Security Component hashing process, you need to use the unlockedField method that comes with the FormHelper class as such:
$this->Form->unlockField('field');
If this does not work, you will need to provide us with the pertinent code
I was getting the similar error in cakephp 3.4 I was using the simple html form and input fields. I was passing the input fields data in array. like below:-
<form action="" method="post">
<input name="data[1][category_1]" id="category_1">
</form>
Then i do some R&D and found that we need to use the cakephp form helper to create the form and its fields like below :-
In case of pass form data in array
<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
<?= $this->Form->input("Data.1.category_1"); ?>
<?= $this->Form->end() ?>
In case of simple input fields you can do the code like below
<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
<?= $this->Form->input("category"); ?>
<?= $this->Form->end() ?>
This work form me and resolve the error Unexpected field in POST data in cakephp 3.4

Get checkbox value of own made form type in Symfony

I have added the following form typo in Symfony to my form. As it is not a member of the entity I need to handle it manually in the controller. How can i get the checkbox value in my controller?
->add('showUrl', 'checkbox', array(
'mapped' => false,
))
This is the generated html in the form:
<input type="checkbox" id="cuslocation_accountreg_showUrl" name="cuslocation[accountreg][showUrl]" required="required" value="1">
$form->getData()['showUrl']
or
$form->get('showUrl')->getData()
or
$form['showUrl']->getData()

symfony2 comparing hidden field with its hash with form validation

I would like to know how to compare fields in symfony2 form with custom validation.
In particular I want to compare a simple hidden field with its hash.
<input type="hidden" name="smoke" value="1" />
<input type="hidden" name="smoke_hash" value="kahsjkdasjkdh3iuy84932798" />
Something like "repeated Field" but validated with my own logic.
But more something like this:
use Symfony\Component\Validator\Constraints\HashMatchString;
$builder
->add('smoke', 'hidden', array(
'data' => 1,
)
)
->add('smoke_hash', 'hidden', array(
'constraints' => array(
new HashMatchString('smoke')
),
)
)
;
Form Goodness in Symfony 2.1
I’ve already see the solution of Steven Brown (http://www.yewchube.com/2011/08/symfony-2-field-comparison-validator/) but is one year ago with multiple touches on core files...
SOLVED
I’ve created a gist: Gist
Just add validation method to your entity http://symfony.com/doc/current/book/validation.html#getters

Drupal Custom Module / Form Question: Adding an array of fields

I'm creating a custom module where I'd like to have the "add another item" functionality for a particular field, but I can't seem to figure out what I need to do in order to accomplish this... I've been going through Drupal forums and their Forms API Reference, but I must not be getting something.... I'm using Drupal 6.20, and in my module, I tried:
$form['options'] = array(
'#title' => t('Options'),
'#type' => 'fieldset',
);
$form['options']['address'] = array(
'#type'=>'textfield',
'#title'=>t('Address'),
'#tree' => 1,
);
Thinking I would get an text input that looked like this:
<input type="text" class="form-text text" value="" size="60" id="edit-address-0-value" name="address[0][value]">
But, I just get an input that looks like this:
<input type="text" class="form-text" value="" size="60" id="edit-address" name="address" maxlength="128">
You need to set #tree on the element above the one you want to duplicate. FAPI will store values in a tree structure from that element on downwards.
To get a name like address[0][value] you will need something like
$form['options']['address'] = array(
'#tree' => TRUE,
);
$form['options']['address'][0] = array(
'#tree' => TRUE,
);
$form['options']['address'][0]['value'] = array(
'#type'=>'textfield',
'#title'=>t('Address'),
);
But you don't need the [value] part unless you are actually trying to achieve multi-valued grouped fields or if your field has a complex (custom) data type implemented with multiple PHP values (ie. latitude/longitude, start/stop dates, etc.).
You will also probably need to store the number of values in something like $form['options']['#nb_values'] or in an hidden field (if you plan to add the additional fields to the form using JavaScript).

Resources