Question: We are localizing our website and we want users to be able to pay in USD and EUR, based on their location. Everything is in place, we detect the country based on IP and we choose a currency accordingly. However there is one fraud possibility we haven't tackled yet. 

We want prevent our users from paying in USD (the USD price is cheaper) when they are actually in Europe (in case they use a proxy), so I want to use Paypal's residence\_country for a double check during or even before payment.

I know I can check the residence\_country of the user in the POST data sent to our Paypal IPN notify url. If the country is not the US, I can decline any USD payment by automatically refunding the amount back to the user. Refunding however is not very neat and I noticed that for example Spotify is able to decline a subscription payment before you even pay. So they don't work with refunding. How does this work? How are they able to decline a payment via Paypal before the payment is finished?

It would be nice to be able to pass a country code to Paypal saying "this payment can only be done by a US citizen" but I haven't found such option in the docs here: <https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/>

(Yes we use recurring payments for Payments Standard)

Thanks :)

Answer: 
The best and recommended way is to use symfony's form builder 

```
public function updatePartsAction(Request $request, $subid) {
    $r = $this->getDoctrine()->getManager();

    $entity = $r->getRepository('MainBundle:MainSub')->findOneById($subid);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Parts entity to edit.');
    }
    $form= $this->createFormBuilder($entity)
           ->add('part')
           ->add('batch')
           .... and so on the properties from your entity that you want them to edit
           ->getForm();
 if ($this->getRequest()->getMethod() == "POST") {
        $form->handleRequest($request)
        if ($form->isValid()) {
        $r->persist($form->getData());
        $r->flush();
        }
  }

}

```

In twig just render your `{{ form(form) }}`

The other way you ask for is not recommended and not a good practice but it depends on you how you are going to code your app the good way or bad way

```
public function updatePartsAction(Request $request, $subid) {
    $r = $this->getDoctrine()->getManager();

    $entity = $r->getRepository('MainBundle:MainSub')->findOneById($subid);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Parts entity to edit.');
    }
  if ($this->getRequest()->getMethod() == "POST") {
    $entity->setPath('get values from request')
     and others setters to which you want them to edit        
        $r->persist($entity);
        $r->flush();

  }
}

```
That concept goes against the entire purpose of MVC (trying to do it in the template/view), so I'm not sure what you meant by your last statement.

However, in your controller you should access the entity (model) via the entities methods. 

I.e. if I have a $user entity with a username property, I should have a setUsername method and can do:

```
 $user->setUsername('theusername');
 $em->persist($user); 
 $em->flush();

```

Note that I used $em instead of your $r out of habit (it's what the documentation shows and what most programmers will use).

Also, using the form component is still a better method in the long haul.