4

TL;DR: I'm trying to implement subscription to my store, but the "paypalobjects.com/api/checkout.js" redirects to "sandbox.paypal.com/webapps/hermes/error". Regular payments work as intended. I'm using Express Checkout advanced server integrations.

My Paypal.Button:

paypal.Button.render({

        env: 'sandbox', // Optional: specify 'sandbox' environment

        payment: function(resolve, reject) {


            const token = localStorage.getItem('_token').split(' ')[1];
            if(!subscribe){
              var CREATE_PAYMENT_URL = `/store/${store}/paypal/create-payment/${orderId}?token=${token}`;
            }else{
              var CREATE_PAYMENT_URL = `/store/${store}/subscribe/paypal/create-payment/${orderId}?token=${token}`;
            }

            paypal.request.post(CREATE_PAYMENT_URL)
                .then(function(data) { resolve(data.id); })
                .catch(function(err) { console.log(err); });
        },

        onAuthorize: function(data) {

            const token = localStorage.getItem('_token').split(' ')[1];
              if(!subscribe){
                var EXECUTE_PAYMENT_URL = `/store/${store}/paypal/execute-payment?token=${token}`;
              }else{
                var EXECUTE_PAYMENT_URL = `/store/${store}/subscribe/paypal/execute-payment?token=${token}`;
              }


            paypal.request.post(EXECUTE_PAYMENT_URL,
                    { paymentID: data.paymentID, payerID: data.payerID })

                .then(function(data) {

                })
                .catch(function(err) { console.log("error " + err);});
        },
        onCancel: function(data){

          cancel();
          this.destroy();
        },
        onError: function (err) {
          console.log("ERROR OCCURRED!");
          console.log(err);
        }

  }, '#paypal-button');

Not really relevant, but my backend looks like this(with testdata):

public function createPaypalOrder(Request $request, $store, $orderId){

      $order = Order::with(['user', 'whitelabel'])->where('id', $orderId)->first();


      $amout = array(
        'value' => (string) $order->price/100,
        'currency' => 'NOK',
      );

      $shippingandtax = array(
        'value' => '0',
        'currency' => 'NOK',
      );

      $charge_models = array([
        'type'=> 'SHIPPING',
        'amount'=> $shippingandtax,
      ],
      [
        'type'=> 'TAX',
        'amount'=> $shippingandtax,
      ]);

      $payment_definitions_creation = array();
      array_push($payment_definitions_creation,[
        'name' => 'Regular Payment Definition',
        'type' => 'REGULAR',
        'frequency' => 'MONTH',
        'frequency_interval'=> '2',
        'amount' => $amout,
        'cycles' => '12',
        'charge_models' => $charge_models
      ]);

      $format = Config::get('constants.FRONTEND_URL')[env('APP_ENV')];
      $redirectBase = sprintf($format, $order->whitelabel->subdomain, 'orders/?order=' . $order->id);


      $merchant_preferences_temp = array(
        'value' => '0',
        'currency' => 'NOK'
      );
      $merchant_preferences = array(
          "setup_fee" => $merchant_preferences_temp,
          'return_url' => "http://www.vg.no",
          'cancel_url' => "http://www.yahoo.no",
          'auto_bill_amount' => 'YES',
          'initial_fail_amount_action' => 'CONTINUE',
          'max_fail_attempts' => '0'
      );

      $payment_definitions = array();
      array_push($payment_definitions, $payment_definitions_creation);

      $name = 'Monthly subscription to ' . (string)$order->whitelabel->title;
      $body = array(
        'name' => $name,
        'description' => 'Subscribtion.',
        'type' => 'fixed',
        'payment_definitions' => $payment_definitions_creation,
        "merchant_preferences"=> $merchant_preferences,
      );


      $token = $this->getPaypalToken($order);

      $client = new \GuzzleHttp\Client();
      $response = $client->post('https://api.sandbox.paypal.com/v1/payments/billing-plans', [
        'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token],
        'json' => $body,
      ]);

      $paypalOrderCreation = json_decode($response->getBody());

      // add stuff to db
      $order->setTransactionId($paypalOrderCreation->id);
      return json_encode($paypalOrderCreation);

    }

My backend returns a valid response from paypal with the id of the order and the state "CREATED". (And lots of other data..)

{"id":"P-0SE01606VF925501Y2UAKG3Y","state":"CREATED","name":"Monthly subscription to Paypal","description":"Subscribtion.","type":"FIXED","payment_definitions":[{"id":"PD-35U317461H38251442UAKG4A","name":"Regular Payment Definition","type":"REGULAR","frequency":"Month","amount":{"currency":"NOK","value":"500"},"cycles":"12","charge_models":[{"id":"CHM-7T021625H451740052UAKG4A","type":"SHIPPING","amount":{"currency":"NOK","value":"0"}},{"id":"CHM-313690493W320615U2UAKG4A","type":"TAX","amount":{"currency":"NOK","value":"0"}}],"frequency_interval":"2"}],"merchant_preferences":{"setup_fee":{"currency":"NOK","value":"0"},"max_fail_attempts":"0","return_url":"http:\/\/www.vg.no","cancel_url":"http:\/\/www.yahoo.no","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2017-01-25T09:41:45.967Z","update_time":"2017-01-25T09:41:45.967Z","links":[{"href":"https:\/\/api.sandbox.paypal.com\/v1\/payments\/billing-plans\/P-0SE01606VF925501Y2UAKG3Y","rel":"self","method":"GET"}]}

Now my problem is that when my paypal.button receives this response it processes the information and redirects me to "sandbox.paypal.com/webapps/hermes/error", which is somewhat hard to debug.

Thanks :)

LordMarty
  • 1,551
  • 1
  • 12
  • 17

1 Answers1

0

The problem was an internal issue at Paypal. Works now.

LordMarty
  • 1,551
  • 1
  • 12
  • 17