|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * PayPal REST Complete Subscription Request |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Omnipay\PayPal\Message; |
| 7 | + |
| 8 | +/** |
| 9 | + * PayPal REST Complete Subscription Request |
| 10 | + * |
| 11 | + * Use this call to create a billing agreement after the buyer approves it. |
| 12 | + * |
| 13 | + * Note: This request is only necessary for PayPal payments. |
| 14 | + * https://developer.paypal.com/docs/limited-release/reference-transactions/#create-billing-agreement-token |
| 15 | + * |
| 16 | + * ### Request Data |
| 17 | + * |
| 18 | + * Pass the token in the URI of a POST call to execute the subscription |
| 19 | + * agreement after buyer approval. You can find the token in the execute |
| 20 | + * link returned by the request to create a billing agreement. |
| 21 | + * |
| 22 | + * No other data is required. |
| 23 | + * |
| 24 | + * ### Example |
| 25 | + * |
| 26 | + * To create the agreement, see the code example in RestCreateCardRequest. |
| 27 | + * |
| 28 | + * At the completion of a CreateCard call, the customer should be |
| 29 | + * redirected to the redirect URL contained in $response->getRedirectUrl(). Once |
| 30 | + * the customer has approved the agreement and be returned to the returnUrl |
| 31 | + * in the call. The returnUrl can contain the following code to complete |
| 32 | + * the agreement: |
| 33 | + * |
| 34 | + * <code> |
| 35 | + * // Create a gateway for the PayPal REST Gateway |
| 36 | + * // (routes to GatewayFactory::create) |
| 37 | + * $gateway = Omnipay::create('PayPal_Rest'); |
| 38 | + * |
| 39 | + * // Initialise the gateway |
| 40 | + * $gateway->initialize(array( |
| 41 | + * 'clientId' => 'MyPayPalClientId', |
| 42 | + * 'secret' => 'MyPayPalSecret', |
| 43 | + * 'testMode' => true, // Or false when you are ready for live transactions |
| 44 | + * )); |
| 45 | + * |
| 46 | + * // Crate a card |
| 47 | + * $transaction = $gateway->completeCreateCard(array( |
| 48 | + * 'transactionReference' => $subscription_id, |
| 49 | + * )); |
| 50 | + * $response = $transaction->send(); |
| 51 | + * if ($response->isSuccessful()) { |
| 52 | + * echo "Complete Subscription transaction was successful!\n"; |
| 53 | + * $subscription_id = $response->getTransactionReference(); |
| 54 | + * echo "Subscription reference = " . $subscription_id; |
| 55 | + * } |
| 56 | + * </code> |
| 57 | + * |
| 58 | + * Note that the subscription_id that you get from calling the response's |
| 59 | + * getTransactionReference() method at the end of the completeSubscription |
| 60 | + * call will be different to the one that you got after calling the response's |
| 61 | + * getTransactionReference() method at the end of the createSubscription |
| 62 | + * call. The one that you get from completeSubscription is the correct |
| 63 | + * one to use going forwards (e.g. for cancelling or updating the subscription). |
| 64 | + * |
| 65 | + * ### Request Sample |
| 66 | + * |
| 67 | + * This is from the PayPal web site: |
| 68 | + * |
| 69 | + * <code> |
| 70 | + * curl -v POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-0JP008296V451950C/agreement-execute \ |
| 71 | + * -H 'Content-Type:application/json' \ |
| 72 | + * -H 'Authorization: Bearer <Access-Token>' \ |
| 73 | + * -d '{}' |
| 74 | + * </code> |
| 75 | + * |
| 76 | + * ### Response Sample |
| 77 | + * |
| 78 | + * This is from the PayPal web site: |
| 79 | + * |
| 80 | + * <code> |
| 81 | + * { |
| 82 | + * "id": "I-0LN988D3JACS", |
| 83 | + * "links": [ |
| 84 | + * { |
| 85 | + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS", |
| 86 | + * "rel": "self", |
| 87 | + * "method": "GET" |
| 88 | + * } |
| 89 | + * ] |
| 90 | + * } |
| 91 | + * </code> |
| 92 | + * |
| 93 | + * @link https://developer.paypal.com/docs/api/#execute-an-agreement |
| 94 | + * @see RestCreateSubscriptionRequest |
| 95 | + * @see Omnipay\PayPal\RestGateway |
| 96 | + */ |
| 97 | +class RestCompleteCreateCardRequest extends AbstractRestRequest |
| 98 | +{ |
| 99 | + public function getData() |
| 100 | + { |
| 101 | + $this->validate('transactionReference'); |
| 102 | + |
| 103 | + return ['token_id' => $this->getTransactionReference()]; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Get transaction endpoint. |
| 108 | + * |
| 109 | + * Subscriptions are executed using the /billing-agreements resource. |
| 110 | + * |
| 111 | + * @return string |
| 112 | + */ |
| 113 | + protected function getEndpoint() |
| 114 | + { |
| 115 | + return parent::getEndpoint() . '/billing-agreements/agreements'; |
| 116 | + } |
| 117 | +} |
0 commit comments