Billing Agreement PHP SDK
TimeMeAS
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Dec-29-2018
04:35 PM
Hi,
Attempting to create a billing agreement, but I'm receiving the following error:
[30-12-2018 01:33:42] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/oauth2/token [30-12-2018 01:33:43] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers : POST /v1/oauth2/token HTTP/1.1, Host: api.sandbox.paypal.com, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.13.0 (platform-ver=7.0.28; bit=64; os=Darwin_18.2.0; machine=x86_64; crypto-lib-ver=1.0.2n; curl=7.45.0), Authorization: Basic QWIzaVlNeTlnbXQzamQ5TEVaUkVSZnNWNmJUaFY4UHZac3RjcVNVNjhQWDNPQzByall3TnhFOXZwTlo1eVVabFVHX2lqZzYwUERiaElCZkE6RUxhXzBPTnpTR1A3VXBkOGM3NU9wdHkwelRiMVBlOWpsWk1MNVJmRnhOUDZNcEl5a3FnREZHbHY4b0l4ZFQ5TTZ0NzVnZXpuNFRNUXhJREs=, Accept: */*, Content-Length: 29, Content-Type: application/x-www-form-urlencoded, , [30-12-2018 01:33:43] PayPal\Core\PayPalHttpConnection : DEBUG: Request Data : grant_type=client_credentials -------------------------------------------------------------------------------------------------------------------------------- [30-12-2018 01:33:43] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 200 [30-12-2018 01:33:43] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers : Date: Sun, 30 Dec 2018 00:33:42 GMT, Server: Apache, paypal-debug-id: 983abb91dccbd, X-PAYPAL-TOKEN-SERVICE: IAAS, HTTP_X_PP_AZ_LOCATOR: sandbox.slc, Paypal-Debug-Id: 983abb91dccbd, Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT, Vary: Authorization, Content-Length: 1159, Connection: close, Content-Type: application/json, [30-12-2018 01:33:43] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data : {"scope":"https://uri.paypal.com/services/paypalhere https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/payments/refund https://uri.paypal.com/services/applications/webhooks https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/payments/payment/authcapture https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/payments/refund https://uri.paypal.com/services/reporting/search/read https://uri.paypal.com/services/identity/activities https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/disputes/read-buyer https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/sale/.*/refund openid https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/realtimepayment","nonce":"2018-12-30T00:01:29Zl-SEDt4mYEKZzfE0z2iTIR8ZXU5NuIh3HpaPr3eJMA4","access_token":"A21AAGh_PiFqUhfIg9o3glWD4h3UwKtt_spywnKZO2U6vrPlgLCjl8WPfxMIorNO9AG-SB9PS1X2a7O_pGWkmkjzGiQKtldmA","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":30467} ================================================================================================================================ [30-12-2018 01:33:43] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/billing-plans/ [30-12-2018 01:33:44] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers : POST /v1/payments/billing-plans/ HTTP/1.1, Host: api.sandbox.paypal.com, Accept: */*, Content-Type: application/json, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.13.0 (platform-ver=7.0.28; bit=64; os=Darwin_18.2.0; machine=x86_64; crypto-lib-ver=1.0.2n; curl=7.45.0), Authorization: Bearer A21AAGh_PiFqUhfIg9o3glWD4h3UwKtt_spywnKZO2U6vrPlgLCjl8WPfxMIorNO9AG-SB9PS1X2a7O_pGWkmkjzGiQKtldmA, Content-Length: 581, , [30-12-2018 01:33:44] PayPal\Core\PayPalHttpConnection : DEBUG: Request Data : {"name":"T-Shirt of the Month Club Plan","description":"Template creation.","type":"fixed","payment_definitions":[{"name":"Regular Payments","type":"REGULAR","frequency":"Month","frequency_interval":"1","cycles":"12","amount":{"value":"490","currency":"NOK"}}],"merchant_preferences":{"return_url":"http://localhost/timeme-web/payments/paypal/executeAgreement/true","cancel_url":"http://localhost/timeme-web/payments/paypal/executeAgreement/false","auto_bill_amount":"yes","initial_fail_amount_action":"CONTINUE","max_fail_attempts":"0","setup_fee":{"value":"1","currency":"NOK"}}} -------------------------------------------------------------------------------------------------------------------------------- [30-12-2018 01:33:44] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 201 [30-12-2018 01:33:44] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers : Date: Sun, 30 Dec 2018 00:33:43 GMT, Server: Apache, paypal-debug-id: 4a907bbdd883d, Content-Language: *, HTTP_X_PP_AZ_LOCATOR: sandbox.slc, Paypal-Debug-Id: 4a907bbdd883d, Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT, Vary: Authorization, Content-Length: 883, Connection: close, Content-Type: application/json, [30-12-2018 01:33:44] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data : {"id":"P-29U54571ET93446287SD6MPI","state":"CREATED","name":"T-Shirt of the Month Club Plan","description":"Template creation.","type":"FIXED","payment_definitions":[{"id":"PD-8JL75064T9949072M7SD6MPI","name":"Regular Payments","type":"REGULAR","frequency":"Month","amount":{"currency":"NOK","value":"490"},"cycles":"12","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"NOK","value":"1"},"max_fail_attempts":"0","return_url":"http://localhost/timeme-web/payments/paypal/executeAgreement/true","cancel_url":"http://localhost/timeme-web/payments/paypal/executeAgreement/false","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2018-12-30T00:33:43.997Z","update_time":"2018-12-30T00:33:43.997Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-29U54571ET93446287SD6MPI","rel":"self","method":"GET"}]} ================================================================================================================================ [30-12-2018 01:33:44] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/
Here is my PHP function:
public function createBillingAgreementPayPalAction($planId = 1, $employees = 10) { /*if ($this->member) { return json_encode([ 'response' => 'error', 'message' => 'You may only do this at registration. Please contact support to sign an agreement.' ]); }*/ $billingPlan = \BillingProducts::getByID($planId); $plan = new Plan(); $plan->setName('T-Shirt of the Month Club Plan'); $plan->setDescription('Template creation.'); $plan->setType('fixed'); $paymentDefinition = new PaymentDefinition(); $paymentDefinition->setName('Regular Payments'); $paymentDefinition->setType('REGULAR'); $paymentDefinition->setFrequency('Month'); $paymentDefinition->setFrequencyInterval("1"); $paymentDefinition->setCycles("12"); $paymentDefinition->setAmount(new Currency(array( 'value' => ($billingPlan->price * $employees), 'currency' => PayPalHandler::CURRENCY ))); $merchantPreferences = new MerchantPreferences(); $merchantPreferences->setReturnUrl("http://localhost/timeme-web/payments/paypal/executeAgreement/true"); $merchantPreferences->setCancelUrl("http://localhost/timeme-web/payments/paypal/executeAgreement/false"); $merchantPreferences->setAutoBillAmount("yes"); $merchantPreferences->setInitialFailAmountAction("CONTINUE"); $merchantPreferences->setMaxFailAttempts("0"); $merchantPreferences->setSetupFee(new Currency(array( 'value' => 1, 'currency' => PayPalHandler::CURRENCY ))); $plan->setPaymentDefinitions(array($paymentDefinition)); $plan->setMerchantPreferences($merchantPreferences); $newPlan = $plan->create($this->apiContext); $agreement = new Agreement(); $agreement->setName('Base Agreement'); $agreement->setDescription('Basic Agreement'); $agreement->setStartDate(date("c", strtotime('+1 month', strtotime(date('Y-m-d H:i:s'))))); $agreement->setPlan($newPlan->getId()); $payer = new Payer(); $payer->setPaymentMethod('paypal'); $agreement->setPayer($payer); $request = clone $agreement; try { $agreement = $agreement->create($this->apiContext); $approvalUrl = $agreement->getApprovalLink(); } catch (\Exception $ex) { echo json_encode([ 'response' => 'error', 'message' => (string)$ex ]); exit(1); } echo json_encode([ 'message' => "<a href='$approvalUrl' >$approvalUrl</a>, request: " . $request . ", agreement: " . $agreement ]); return $agreement; }
Thanks in advance.
1 REPLY 1
TimeMeAS
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dec-29-2018
04:37 PM
It's saying Incoming JSON request does not map to API request, but I don't understand what parameter is wrong?

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- Sandbox account collect billing and shipping address in Sandbox Environment
- Enabled billing address for sandbox in Sandbox Environment
- How to integrate PayPal during user signup to avoid re-entering credentials for future payments? in REST APIs
- subscription_id has disappeared in REST APIs
- Why does PayPal make it difficult to send an item to a different shipping address from billing? in PayPal Upgrade Community