title: PayPal API with Laravel - Updating of data
body: <p>I'm trying to implement the <code>API</code> of <code>PayPal payment</code> with <code>Laravel 5.1</code>. But when I log in to <code>PayPal (sandbox)</code>, it uses the address I used in my account, and also it uses the name from PayPal account not the data from my website. That's my problem.</p>
  
  <p>I want to use the data from my website because it doesn't make sense if I enter the shipping address (for example) from my website and not using it. Please see my code below for reference (Or comment down below for some details from me).</p>
  
  <pre><code>class PaypalPaymentController extends BaseController
  {
  
      private $_api_context;
  
      public function __construct(){
          $paypal_conf = \Config::get('paypal');
  
          $this-&gt;_api_context = new ApiContext(new OAuthTokenCredential(
              $paypal_conf['client_id'],
              $paypal_conf['secret']
          ));
  
          $this-&gt;_api_context-&gt;setConfig($paypal_conf['settings']);
      }
  
      public function payWithPaypal(Request $request){
          $payer = new Payer;
          $payer-&gt;setPaymentMethod('paypal');
  
          $price = 0;
  
          switch($request-&gt;get('amount')) {
              case '10 books':
                  $price = 6200;
                  break;
              case '20 books':
                  $price = 12200;
                  break;
              case '50 books':
                  $price = 25200;
                  break;
              default:
                  return redirect()
                          -&gt;route('bookstore.shipping')
                          -&gt;with('danger', 'Please select the right amount of book/s.');
                  break;
          }
  
          $item1 = new Item();
          $item1-&gt;setName($request-&gt;get('amount'))
                  -&gt;setCurrency('PHP')
                  -&gt;setQuantity(1)
                  -&gt;setPrice($price);
  
          $item_list = new ItemList();
          $item_list-&gt;setItems([$item1]);
  
          $amount = new Amount();
          $amount-&gt;setCurrency('PHP')
                  -&gt;setTotal($price);
  
          $transaction = new Transaction();
          $transaction-&gt;setAmount($amount)
                      -&gt;setItemList($item_list)
                      -&gt;setDescription('Books transaction');
  
          $redirect_urls = new RedirectUrls();
          $redirect_urls-&gt;setReturnUrl(route('bookstore.payment-status'))
                          -&gt;setCancelUrl(route('bookstore.payment-status'));
  
          $payment = new Payment();
          $payment-&gt;setIntent('Sale')
                  -&gt;setPayer($payer)
                  -&gt;setRedirectUrls($redirect_urls)
                  -&gt;setTransactions([$transaction]);
  
           $patchReplace = new Patch();
           $patchReplace-&gt;setOp('add')
                      -&gt;setPath('/transactions/0/item_list/shipping_address')
                      -&gt;setValue(json_decode('{
                          "line1": "345 Lark Ave",
                          "city": "Montreal",
                          "state": "QC",
                          "postal_code": "H1A4K2",
                          "country_code": "CA"
                      }'));
  
           $patchRequest = (new PatchRequest())-&gt;setPatches([$patchReplace]);
  
  
          try{
  
              $payment-&gt;create($this-&gt;_api_context);
              $payment-&gt;update($patchRequest, $this-&gt;_api_context);
  
          } catch(\Palpal\Exception\PPConnectionException $e){
  
              if(\Config::get('app.debug')){
                  return redirect()
                          -&gt;route('bookstore.shipping')
                          -&gt;with('danger', 'Connection Timeout.');
              }
  
              return redirect()
                      -&gt;route('bookstore.shipping')
                      -&gt;with('danger', 'Some error occured, sorry for the inconvenience.');
          }
  
          foreach($payment-&gt;getLinks() as $link){
              if($link-&gt;getRel() == 'approval_url'){
                  $redirect_url = $link-&gt;getHref();
                  break;
              }
          }
  
          Session::put('paypal_payment_id', $payment-&gt;getId());
  
          if(isset($redirect_url)){
              return Redirect::away($redirect_url);
          }
  
          return redirect()
                  -&gt;route('bookstore.shipping')
                  -&gt;with('danger', 'Unknown error occured.');
      }
  
      public function getPaymentStatus(){
          $payment_id = Session::get('paypal_payment_id');
          Session::forget('paypal_payment_id');
  
          if(empty(Input::get('PayerID')) || empty(Input::get('token'))){
              return redirect()
                      -&gt;route('bookstore.shipping')
                      -&gt;with('danger', 'Payment failed.');
          }
  
          $payment = Payment::get($payment_id, $this-&gt;_api_context);
          $execution = new PaymentExecution();
          $execution-&gt;setPayerId(Input::get('PayerID'));
  
          $result = $payment-&gt;execute($execution, $this-&gt;_api_context);
  
          if($result-&gt;getState() == 'approved'){
              // Send Email
              $email_data = [
                  'number_of_books' =&gt; $payment-&gt;transactions[0]-&gt;item_list-&gt;items[0]-&gt;name,
                  'shipping' =&gt; [
                      'street' =&gt; $payment-&gt;payer-&gt;payer_info-&gt;shipping_address-&gt;line1,
                      'city' =&gt; $payment-&gt;payer-&gt;payer_info-&gt;shipping_address-&gt;city,
                      'state' =&gt; $payment-&gt;payer-&gt;payer_info-&gt;shipping_address-&gt;state,
                      'country' =&gt; $payment-&gt;payer-&gt;payer_info-&gt;shipping_address-&gt;country_code,
                  ]
              ];
  
              // Send email function here ...
  
              return redirect()
                      -&gt;route('bookstore.shipping')
                      -&gt;with('success', 'Transaction payment success!');
          }
  
          return redirect()
                  -&gt;route('bookstore.shipping')
                  -&gt;with('danger', 'Payment failed.');
      }
  
  }
  </code></pre>
  
  <p>I also reviewed <a href="https://stackoverflow.com/questions/39927124/paypal-php-set-no-shipping">this link</a> but it seems like it cannot answer my problem. Also, <code>what if</code> the country has a province? How can we add that?</p>
  
  <p><strong>Update 1</strong></p>
  
  <ol>
  <li>Added new <code>Patch()</code> class.</li>
  <li>Edited Code in <code>Try Catch</code>.</li>
  </ol>
  
  <hr>
  
  <p>Note: The <code>accepted</code> answer will also receive the <code>bounty</code> plus the <code>up</code>.</p>
  
  <p><strong>Update 2 with Tutorial</strong></p>
  
  <ol>
  <li><p>For PHP/Laravel (I'm currently using v5.1), install this package
  <a href="https://github.com/paypal/PayPal-PHP-SDK" rel="nofollow noreferrer">paypal/rest-api-sdk-php</a></p></li>
  <li><p><a href="https://www.sandbox.paypal.com/ph/webapps/mpp/merchant" rel="nofollow noreferrer">Create Sandbox account in PayPal</a>. Choose <a href="https://www.paypal.com/ph/signup/account?country.x=PH&amp;locale.x=en_PH" rel="nofollow noreferrer">Buy with Paypal</a>.</p></li>
  <li><p>Continue until you see options, choose <a href="https://www.paypal.com/ph/webapps/mpp/online-shopping" rel="nofollow noreferrer">Shop the world</a>.</p></li>
  <li><p>Login to <a href="https://developer.paypal.com/" rel="nofollow noreferrer">developer.paypal.com</a>.</p></li>
  <li><p>Click <a href="https://developer.paypal.com/developer/accounts/" rel="nofollow noreferrer">Accounts</a>. Click <a href="https://developer.paypal.com/developer/accounts/create" rel="nofollow noreferrer">Create Account</a>.</p></li>
  <li><p>Choose what country you want. Choose Personal (Buyer Account) in Account Type.</p></li>
  <li><p>Add email address, avoid to use <code>-</code>. Use <code>_</code> instead.</p></li>
  <li><p>Enter how much PayPal Balance you want.</p></li>
  <li><p>Click Create Account.</p></li>
  </ol>
  
  <p><strong>Make it live?</strong></p>
  
  <p><a href="https://github.com/paypal/PayPal-PHP-SDK/wiki/Going-Live" rel="nofollow noreferrer">https://github.com/paypal/PayPal-PHP-SDK/wiki/Going-Live</a></p>