| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example demonstrating the ContributionPage.create API. |
| 4 | * |
| 5 | * @return array |
| 6 | * API result array |
| 7 | */ |
| 8 | function contribution_page_create_example() { |
| 9 | $params = array( |
| 10 | 'title' => 'Test Contribution Page', |
| 11 | 'financial_type_id' => 1, |
| 12 | 'currency' => 'NZD', |
| 13 | 'goal_amount' => 34567, |
| 14 | 'is_pay_later' => 1, |
| 15 | 'is_monetary' => TRUE, |
| 16 | ); |
| 17 | |
| 18 | try{ |
| 19 | $result = civicrm_api3('ContributionPage', 'create', $params); |
| 20 | } |
| 21 | catch (CiviCRM_API3_Exception $e) { |
| 22 | // Handle error here. |
| 23 | $errorMessage = $e->getMessage(); |
| 24 | $errorCode = $e->getErrorCode(); |
| 25 | $errorData = $e->getExtraParams(); |
| 26 | return array( |
| 27 | 'error' => $errorMessage, |
| 28 | 'error_code' => $errorCode, |
| 29 | 'error_data' => $errorData, |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | return $result; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Function returns array of result expected from previous function. |
| 38 | * |
| 39 | * @return array |
| 40 | * API result array |
| 41 | */ |
| 42 | function contribution_page_create_expectedresult() { |
| 43 | |
| 44 | $expectedResult = array( |
| 45 | 'is_error' => 0, |
| 46 | 'version' => 3, |
| 47 | 'count' => 1, |
| 48 | 'id' => 1, |
| 49 | 'values' => array( |
| 50 | '1' => array( |
| 51 | 'id' => '1', |
| 52 | 'title' => 'Test Contribution Page', |
| 53 | 'intro_text' => '', |
| 54 | 'financial_type_id' => '1', |
| 55 | 'payment_processor' => '', |
| 56 | 'is_credit_card_only' => '', |
| 57 | 'is_monetary' => '1', |
| 58 | 'is_recur' => '', |
| 59 | 'is_confirm_enabled' => '', |
| 60 | 'recur_frequency_unit' => '', |
| 61 | 'is_recur_interval' => '', |
| 62 | 'is_recur_installments' => '', |
| 63 | 'is_pay_later' => '1', |
| 64 | 'pay_later_text' => '', |
| 65 | 'pay_later_receipt' => '', |
| 66 | 'is_partial_payment' => '', |
| 67 | 'initial_amount_label' => '', |
| 68 | 'initial_amount_help_text' => '', |
| 69 | 'min_initial_amount' => '', |
| 70 | 'is_allow_other_amount' => '', |
| 71 | 'default_amount_id' => '', |
| 72 | 'min_amount' => '', |
| 73 | 'max_amount' => '', |
| 74 | 'goal_amount' => '34567', |
| 75 | 'thankyou_title' => '', |
| 76 | 'thankyou_text' => '', |
| 77 | 'thankyou_footer' => '', |
| 78 | 'is_for_organization' => '', |
| 79 | 'for_organization' => '', |
| 80 | 'is_email_receipt' => '', |
| 81 | 'receipt_from_name' => '', |
| 82 | 'receipt_from_email' => '', |
| 83 | 'cc_receipt' => '', |
| 84 | 'bcc_receipt' => '', |
| 85 | 'receipt_text' => '', |
| 86 | 'is_active' => '1', |
| 87 | 'footer_text' => '', |
| 88 | 'amount_block_is_active' => '', |
| 89 | 'start_date' => '', |
| 90 | 'end_date' => '', |
| 91 | 'created_id' => '', |
| 92 | 'created_date' => '', |
| 93 | 'currency' => 'NZD', |
| 94 | 'campaign_id' => '', |
| 95 | 'is_share' => '', |
| 96 | 'is_billing_required' => '', |
| 97 | ), |
| 98 | ), |
| 99 | ); |
| 100 | |
| 101 | return $expectedResult; |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * This example has been generated from the API test suite. |
| 106 | * The test that created it is called "testCreateContributionPage" |
| 107 | * and can be found at: |
| 108 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionPageTest.php |
| 109 | * |
| 110 | * You can see the outcome of the API tests at |
| 111 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 112 | * |
| 113 | * To Learn about the API read |
| 114 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 115 | * |
| 116 | * Browse the api on your own site with the api explorer |
| 117 | * http://MYSITE.ORG/path/to/civicrm/api |
| 118 | * |
| 119 | * Read more about testing here |
| 120 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 121 | * |
| 122 | * API Standards documentation: |
| 123 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 124 | */ |