PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/SetPaymentOptionsReceipt.php

https://gitlab.com/CORP-RESELLER/adaptivepayments-sdk-php
PHP | 221 lines | 173 code | 7 blank | 41 comment | 108 complexity | f70e4bb60e18780a20a1b377c14801a1 MD5 | raw file
  1. <?php
  2. use PayPal\Service\AdaptivePaymentsService;
  3. use PayPal\Types\AP\DisplayOptions;
  4. use PayPal\Types\AP\InitiatingEntity;
  5. use PayPal\Types\AP\InstitutionCustomer;
  6. use PayPal\Types\AP\InvoiceData;
  7. use PayPal\Types\AP\InvoiceItem;
  8. use PayPal\Types\AP\ReceiverIdentifier;
  9. use PayPal\Types\AP\ReceiverOptions;
  10. use PayPal\Types\AP\SenderOptions;
  11. use PayPal\Types\AP\SetPaymentOptionsRequest;
  12. use PayPal\Types\Common\PhoneNumberType;
  13. use PayPal\Types\Common\RequestEnvelope;
  14. require_once('PPBootStrap.php');
  15. define("DEFAULT_SELECT", "- Select -");
  16. /*
  17. * You use the SetPaymentOptions API operation to specify settings for a payment of the actionType CREATE. This actionType is specified in the PayRequest message.
  18. */
  19. $setPaymentOptionsRequest = new SetPaymentOptionsRequest(new RequestEnvelope("en_US"));
  20. /*
  21. * (Required) The pay key that identifies the payment for which you want to set payment options. This is the pay key returned in the PayResponse message.
  22. */
  23. $setPaymentOptionsRequest->payKey = $_POST["payKey"];
  24. // set optional params
  25. /*
  26. * (Optional) Sender's shipping address ID.
  27. */
  28. if($_POST['shippingAddressId'] != "") {
  29. $setPaymentOptionsRequest->shippingAddressId = $_POST['shippingAddressId'];
  30. }
  31. $receiverOptions = new ReceiverOptions();
  32. $setPaymentOptionsRequest->receiverOptions[] = $receiverOptions;
  33. if($_POST['description'] != "") {
  34. /*
  35. * (Optional) A description you want to associate with the payment. This overrides the value of the memo in Pay API for each receiver. If this is not specified the value in the memo will be used.
  36. */
  37. $receiverOptions->description = $_POST['description'];
  38. }
  39. /*
  40. * (Optional) An external reference or identifier you want to associate with the payment.
  41. */
  42. if($_POST['customId'] != "") {
  43. $receiverOptions->customId = $_POST['customId'];
  44. }
  45. /*
  46. *
  47. */
  48. if($_POST['receiverReferrerCode'] != "") {
  49. $receiverOptions->referrerCode = $_POST['receiverReferrerCode'];
  50. }
  51. if($_POST['emailIdentifier'] != "" || ($_POST['phoneNumber'] != "" && $_POST['phoneCountry'] != "")) {
  52. $receiverId = new ReceiverIdentifier();
  53. if($_POST['emailIdentifier'] != "") {
  54. $receiverId->email = $_POST['emailIdentifier'];
  55. }
  56. if($_POST['phoneNumber'] != "" && $_POST['phoneCountry'] != "") {
  57. $receiverId->phone = new PhoneNumberType($_POST['phoneCountry'], $_POST['phoneNumber']);
  58. if($_POST['phoneExtn'] != "") {
  59. $receiverId->phone->extension = $_POST['phoneExtn'];
  60. }
  61. }
  62. $receiverOptions->receiver = $receiverId;
  63. }
  64. $invoiceItems = array();
  65. for($i=0; $i<count($_POST['name']); $i++) {
  66. if($_POST['name'][$i] != "" || $_POST['identifier'][$i] != "" || $_POST['price'][$i] != ""
  67. || $_POST['itemPrice'][$i] != "" || $_POST['itemCount'][$i] != "") {
  68. $item = new InvoiceItem();
  69. if($_POST['name'][$i] != "" ) {
  70. $item->name = $_POST['name'][$i];
  71. }
  72. /*
  73. * (Optional) External reference to item or item ID.
  74. */
  75. if($_POST['identifier'][$i] != "" ) {
  76. $item->identifier = $_POST['identifier'][$i];
  77. }
  78. if($_POST['price'][$i] != "") {
  79. $item->price = $_POST['price'][$i];
  80. }
  81. if($_POST['itemPrice'][$i] != "") {
  82. $item->itemPrice = $_POST['itemPrice'][$i];
  83. }
  84. if($_POST['itemCount'][$i] != "") {
  85. $item->itemCount = $_POST['itemCount'][$i];
  86. }
  87. $invoiceItems[] = $item;
  88. }
  89. }
  90. if(count($invoiceItems) > 0 || $_POST['totalTax'] != "" || $_POST['totalShipping'] != "") {
  91. $receiverOptions->invoiceData = new InvoiceData();
  92. if($_POST['totalTax'] != "") {
  93. $receiverOptions->invoiceData->totalTax = $_POST['totalTax'];
  94. }
  95. if($_POST['totalShipping'] != "" ) {
  96. $receiverOptions->invoiceData->totalShipping = $_POST['totalShipping'];
  97. }
  98. if(count($invoiceItems) > 0) {
  99. $receiverOptions->invoiceData->item = $invoiceItems;
  100. }
  101. }
  102. if($_POST['requireShippingAddressSelection'] != "" || $_POST['senderReferrerCode'] != "" ) {
  103. $setPaymentOptionsRequest->senderOptions = new SenderOptions();
  104. if($_POST['requireShippingAddressSelection'] != "") {
  105. /*
  106. * (Optional) If true, require the sender to select a shipping address during the embedded payment flow; default is false.
  107. */
  108. $setPaymentOptionsRequest->senderOptions->requireShippingAddressSelection = $_POST['requireShippingAddressSelection'];
  109. }
  110. if($_POST['senderReferrerCode'] != "") {
  111. $setPaymentOptionsRequest->senderOptions->referrerCode = $_POST['senderReferrerCode'];
  112. }
  113. }
  114. if($_POST['institutionId'] != "" || $_POST['firstName'] != "" || $_POST['lastName'] != ""
  115. || $_POST['displayName'] != "" || $_POST['institutionMail'] != "" || $_POST['institutionCustomerId'] != ""
  116. || $_POST['countryCode'] != "") {
  117. $institutionCustomer = new InstitutionCustomer();
  118. $setPaymentOptionsRequest->initiatingEntity = new InitiatingEntity();
  119. $setPaymentOptionsRequest->initiatingEntity->institutionCustomer = $institutionCustomer;
  120. /*
  121. * The unique identifier assigned to the institution.
  122. Maximum length: 64 characters
  123. */
  124. if($_POST['institutionId'] != "") {
  125. $institutionCustomer->institutionId = $_POST['institutionId'];
  126. }
  127. if($_POST['firstName'] != "") {
  128. $institutionCustomer->firstName = $_POST['firstName'];
  129. }
  130. if($_POST['lastName'] != "") {
  131. $institutionCustomer->lastName = $_POST['lastName'];
  132. }
  133. if($_POST['displayName'] != "") {
  134. $institutionCustomer->displayName = $_POST['displayName'];
  135. }
  136. if($_POST['institutionMail'] != "") {
  137. $institutionCustomer->email = $_POST['institutionMail'];
  138. }
  139. /*
  140. * The unique identifier assigned to the consumer by the institution.
  141. Maximum length: 64 characters
  142. */
  143. if($_POST['institutionCustomerId'] != "") {
  144. $institutionCustomer->institutionCustomerId = $_POST['institutionCustomerId'];
  145. }
  146. if($_POST['countryCode'] != "") {
  147. $institutionCustomer->countryCode = $_POST['countryCode'];
  148. }
  149. }
  150. if($_POST['emailHeaderImageUrl'] != "" || $_POST['emailMarketingImageUrl'] != "" || $_POST['lastName'] != ""
  151. || $_POST['displayName'] != "") {
  152. $setPaymentOptionsRequest->displayOptions = new DisplayOptions();
  153. if($_POST['emailHeaderImageUrl'] != "") {
  154. $setPaymentOptionsRequest->displayOptions->emailHeaderImageUrl = $_POST['emailHeaderImageUrl'];
  155. }
  156. if($_POST['emailMarketingImageUrl'] != "") {
  157. $setPaymentOptionsRequest->displayOptions->emailMarketingImageUrl = $_POST['emailMarketingImageUrl'];
  158. }
  159. if($_POST['headerImageUrl'] != "") {
  160. $setPaymentOptionsRequest->displayOptions->headerImageUrl = $_POST['headerImageUrl'];
  161. }
  162. if($_POST['businessName'] != "") {
  163. $setPaymentOptionsRequest->displayOptions->businessName = $_POST['businessName'];
  164. }
  165. }
  166. /*
  167. * ## Creating service wrapper object
  168. Creating service wrapper object to make API call and loading
  169. Configuration::getAcctAndConfig() returns array that contains credential and config parameters
  170. */
  171. $service = new AdaptivePaymentsService(Configuration::getAcctAndConfig());
  172. try {
  173. /* wrap API method calls on the service object with a try catch */
  174. $response = $service->SetPaymentOptions($setPaymentOptionsRequest);
  175. } catch(Exception $ex) {
  176. require_once 'Common/Error.php';
  177. exit;
  178. }
  179. ?>
  180. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  181. <html>
  182. <head>
  183. <title>PayPal Adaptive Payments - Set Payment Options</title>
  184. <link href="Common/sdk.css" rel="stylesheet" type="text/css" />
  185. <script type="text/javascript" src="Common/sdk_functions.js"></script>
  186. </head>
  187. <body>
  188. <div id="wrapper">
  189. <img src="https://devtools-paypal.com/image/bdg_payments_by_pp_2line.png"/>
  190. <div id="response_form">
  191. <h3>Set Payment Options</h3>
  192. <?php
  193. $ack = strtoupper($response->responseEnvelope->ack);
  194. if($ack != "SUCCESS"){
  195. echo "<b>Error </b>";
  196. echo "<pre>";
  197. print_r($response);
  198. echo "</pre>";
  199. } else {
  200. echo "<table>";
  201. echo "<tr><td>Ack :</td><td><div id='Ack'>$ack</div> </td></tr>";
  202. echo "</table>";
  203. echo "<pre>";
  204. print_r($response);
  205. echo "</pre>";
  206. }
  207. require_once 'Common/Response.php';
  208. ?>
  209. </div>
  210. </div>
  211. </body>
  212. </html>