{"action":"created","comment":{"url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/comments/52653417","id":52653417,"diff_hunk":"@@ -134,51 +134,72 @@ function civicrm_api3_payment_create(&$params) {\n   }\n   // Get contribution\n   $contribution = civicrm_api3('Contribution', 'getsingle', array('id' => $params['contribution_id']));\n-  if ($contribution['contribution_status'] != 'Partially paid') {\n-    throw new API_Exception('Please select a contribution which has a partial payment');\n+  $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');\n+  if ($contributionStatus[$contribution['contribution_status_id']] != 'Partially paid'\n+    && !($contributionStatus[$contribution['contribution_status_id']] == 'Pending' && $contribution['is_pay_later'] == TRUE)\n+  ) {\n+    throw new API_Exception('Please select a contribution which has a partial or pending payment');\n   }\n   else {\n-    $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params);\n-    $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']);\n-    $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount');\n-    $cmp = bccomp($total, $paid, 5);\n-    if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount\n-      civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));\n+    // Check if pending contribution\n+    $fullyPaidPayLater = FALSE;\n+    if ($contributionStatus[$contribution['contribution_status_id']] == 'Pending') {\n+      $cmp = bccomp($contribution['total_amount'], $params['total_amount'], 5);\n+      // Total payment amount is the whole amount paid against pending contribution\n+      if ($cmp == 0 || $cmp == -1) {\n+        civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));\n+        // Get the trxn\n+        $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');\n+        $ftParams = array('id' => $trxnId['financialTrxnId']);\n+        $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray);\n+        $fullyPaidPayLater = TRUE;\n+      }\n+      else {\n+        civicrm_api3('Contribution', 'create',\n+          array(\n+            'id' => $contribution['id'],\n+            'contribution_status_id' => array_search('Partially paid', $contributionStatus),","path":"api/v3/Payment.php","position":36,"original_position":36,"commit_id":"aca3c96890fb23bebc7caed2d894f95e62536ac0","original_commit_id":"aca3c96890fb23bebc7caed2d894f95e62536ac0","user":{"login":"JoeMurray","id":300943,"avatar_url":"https://avatars.githubusercontent.com/u/300943?v=3","gravatar_id":"","url":"https://api.github.com/users/JoeMurray","html_url":"https://github.com/JoeMurray","followers_url":"https://api.github.com/users/JoeMurray/followers","following_url":"https://api.github.com/users/JoeMurray/following{/other_user}","gists_url":"https://api.github.com/users/JoeMurray/gists{/gist_id}","starred_url":"https://api.github.com/users/JoeMurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoeMurray/subscriptions","organizations_url":"https://api.github.com/users/JoeMurray/orgs","repos_url":"https://api.github.com/users/JoeMurray/repos","events_url":"https://api.github.com/users/JoeMurray/events{/privacy}","received_events_url":"https://api.github.com/users/JoeMurray/received_events","type":"User","site_admin":false},"body":"I'd prefer not put to text into an id field.","created_at":"2016-02-11T19:29:23Z","updated_at":"2016-02-11T19:29:23Z","html_url":"https://github.com/civicrm/civicrm-core/pull/7687#discussion_r52653417","pull_request_url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687","_links":{"self":{"href":"https://api.github.com/repos/civicrm/civicrm-core/pulls/comments/52653417"},"html":{"href":"https://github.com/civicrm/civicrm-core/pull/7687#discussion_r52653417"},"pull_request":{"href":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687"}}},"pull_request":{"url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687","id":57434141,"html_url":"https://github.com/civicrm/civicrm-core/pull/7687","diff_url":"https://github.com/civicrm/civicrm-core/pull/7687.diff","patch_url":"https://github.com/civicrm/civicrm-core/pull/7687.patch","issue_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/7687","number":7687,"state":"open","locked":false,"title":"Crm 16259 2","user":{"login":"pradpnayak","id":2053075,"avatar_url":"https://avatars.githubusercontent.com/u/2053075?v=3","gravatar_id":"","url":"https://api.github.com/users/pradpnayak","html_url":"https://github.com/pradpnayak","followers_url":"https://api.github.com/users/pradpnayak/followers","following_url":"https://api.github.com/users/pradpnayak/following{/other_user}","gists_url":"https://api.github.com/users/pradpnayak/gists{/gist_id}","starred_url":"https://api.github.com/users/pradpnayak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pradpnayak/subscriptions","organizations_url":"https://api.github.com/users/pradpnayak/orgs","repos_url":"https://api.github.com/users/pradpnayak/repos","events_url":"https://api.github.com/users/pradpnayak/events{/privacy}","received_events_url":"https://api.github.com/users/pradpnayak/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-27T22:34:20Z","updated_at":"2016-02-11T19:29:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51e60ee7348218731c860792fc82b297e5b2af93","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687/commits","review_comments_url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687/comments","review_comment_url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/7687/comments","statuses_url":"https://api.github.com/repos/civicrm/civicrm-core/statuses/aca3c96890fb23bebc7caed2d894f95e62536ac0","head":{"label":"JMAConsulting:CRM-16259-2","ref":"CRM-16259-2","sha":"aca3c96890fb23bebc7caed2d894f95e62536ac0","user":{"login":"JMAConsulting","id":2036425,"avatar_url":"https://avatars.githubusercontent.com/u/2036425?v=3","gravatar_id":"","url":"https://api.github.com/users/JMAConsulting","html_url":"https://github.com/JMAConsulting","followers_url":"https://api.github.com/users/JMAConsulting/followers","following_url":"https://api.github.com/users/JMAConsulting/following{/other_user}","gists_url":"https://api.github.com/users/JMAConsulting/gists{/gist_id}","starred_url":"https://api.github.com/users/JMAConsulting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JMAConsulting/subscriptions","organizations_url":"https://api.github.com/users/JMAConsulting/orgs","repos_url":"https://api.github.com/users/JMAConsulting/repos","events_url":"https://api.github.com/users/JMAConsulting/events{/privacy}","received_events_url":"https://api.github.com/users/JMAConsulting/received_events","type":"Organization","site_admin":false},"repo":{"id":16546304,"name":"civicrm-core","full_name":"JMAConsulting/civicrm-core","owner":{"login":"JMAConsulting","id":2036425,"avatar_url":"https://avatars.githubusercontent.com/u/2036425?v=3","gravatar_id":"","url":"https://api.github.com/users/JMAConsulting","html_url":"https://github.com/JMAConsulting","followers_url":"https://api.github.com/users/JMAConsulting/followers","following_url":"https://api.github.com/users/JMAConsulting/following{/other_user}","gists_url":"https://api.github.com/users/JMAConsulting/gists{/gist_id}","starred_url":"https://api.github.com/users/JMAConsulting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JMAConsulting/subscriptions","organizations_url":"https://api.github.com/users/JMAConsulting/orgs","repos_url":"https://api.github.com/users/JMAConsulting/repos","events_url":"https://api.github.com/users/JMAConsulting/events{/privacy}","received_events_url":"https://api.github.com/users/JMAConsulting/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JMAConsulting/civicrm-core","description":"CiviCRM (Core Application and Framework)","fork":true,"url":"https://api.github.com/repos/JMAConsulting/civicrm-core","forks_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/forks","keys_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/teams","hooks_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/hooks","issue_events_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/issues/events{/number}","events_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/events","assignees_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/assignees{/user}","branches_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/branches{/branch}","tags_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/tags","blobs_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/statuses/{sha}","languages_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/languages","stargazers_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/stargazers","contributors_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/contributors","subscribers_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/subscribers","subscription_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/subscription","commits_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/contents/{+path}","compare_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/merges","archive_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/downloads","issues_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/issues{/number}","pulls_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/pulls{/number}","milestones_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/milestones{/number}","notifications_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/labels{/name}","releases_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/releases{/id}","deployments_url":"https://api.github.com/repos/JMAConsulting/civicrm-core/deployments","created_at":"2014-02-05T14:01:01Z","updated_at":"2015-03-25T16:46:36Z","pushed_at":"2016-02-11T12:08:07Z","git_url":"git://github.com/JMAConsulting/civicrm-core.git","ssh_url":"git@github.com:JMAConsulting/civicrm-core.git","clone_url":"https://github.com/JMAConsulting/civicrm-core.git","svn_url":"https://github.com/JMAConsulting/civicrm-core","homepage":null,"size":137346,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"civicrm:master","ref":"master","sha":"4d94cb1ae50819eb0b25b507ab9569b9df9676ad","user":{"login":"civicrm","id":136373,"avatar_url":"https://avatars.githubusercontent.com/u/136373?v=3","gravatar_id":"","url":"https://api.github.com/users/civicrm","html_url":"https://github.com/civicrm","followers_url":"https://api.github.com/users/civicrm/followers","following_url":"https://api.github.com/users/civicrm/following{/other_user}","gists_url":"https://api.github.com/users/civicrm/gists{/gist_id}","starred_url":"https://api.github.com/users/civicrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/civicrm/subscriptions","organizations_url":"https://api.github.com/users/civicrm/orgs","repos_url":"https://api.github.com/users/civicrm/repos","events_url":"https://api.github.com/users/civicrm/events{/privacy}","received_events_url":"https://api.github.com/users/civicrm/received_events","type":"Organization","site_admin":false},"repo":{"id":8495499,"name":"civicrm-core","full_name":"civicrm/civicrm-core","owner":{"login":"civicrm","id":136373,"avatar_url":"https://avatars.githubusercontent.com/u/136373?v=3","gravatar_id":"","url":"https://api.github.com/users/civicrm","html_url":"https://github.com/civicrm","followers_url":"https://api.github.com/users/civicrm/followers","following_url":"https://api.github.com/users/civicrm/following{/other_user}","gists_url":"https://api.github.com/users/civicrm/gists{/gist_id}","starred_url":"https://api.github.com/users/civicrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/civicrm/subscriptions","organizations_url":"https://api.github.com/users/civicrm/orgs","repos_url":"https://api.github.com/users/civicrm/repos","events_url":"https://api.github.com/users/civicrm/events{/privacy}","received_events_url":"https://api.github.com/users/civicrm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/civicrm/civicrm-core","description":"CiviCRM (Core Application and Framework)","fork":false,"url":"https://api.github.com/repos/civicrm/civicrm-core","forks_url":"https://api.github.com/repos/civicrm/civicrm-core/forks","keys_url":"https://api.github.com/repos/civicrm/civicrm-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/civicrm/civicrm-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/civicrm/civicrm-core/teams","hooks_url":"https://api.github.com/repos/civicrm/civicrm-core/hooks","issue_events_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/events{/number}","events_url":"https://api.github.com/repos/civicrm/civicrm-core/events","assignees_url":"https://api.github.com/repos/civicrm/civicrm-core/assignees{/user}","branches_url":"https://api.github.com/repos/civicrm/civicrm-core/branches{/branch}","tags_url":"https://api.github.com/repos/civicrm/civicrm-core/tags","blobs_url":"https://api.github.com/repos/civicrm/civicrm-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/civicrm/civicrm-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/civicrm/civicrm-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/civicrm/civicrm-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/civicrm/civicrm-core/statuses/{sha}","languages_url":"https://api.github.com/repos/civicrm/civicrm-core/languages","stargazers_url":"https://api.github.com/repos/civicrm/civicrm-core/stargazers","contributors_url":"https://api.github.com/repos/civicrm/civicrm-core/contributors","subscribers_url":"https://api.github.com/repos/civicrm/civicrm-core/subscribers","subscription_url":"https://api.github.com/repos/civicrm/civicrm-core/subscription","commits_url":"https://api.github.com/repos/civicrm/civicrm-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/civicrm/civicrm-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/civicrm/civicrm-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/civicrm/civicrm-core/contents/{+path}","compare_url":"https://api.github.com/repos/civicrm/civicrm-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/civicrm/civicrm-core/merges","archive_url":"https://api.github.com/repos/civicrm/civicrm-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/civicrm/civicrm-core/downloads","issues_url":"https://api.github.com/repos/civicrm/civicrm-core/issues{/number}","pulls_url":"https://api.github.com/repos/civicrm/civicrm-core/pulls{/number}","milestones_url":"https://api.github.com/repos/civicrm/civicrm-core/milestones{/number}","notifications_url":"https://api.github.com/repos/civicrm/civicrm-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/civicrm/civicrm-core/labels{/name}","releases_url":"https://api.github.com/repos/civicrm/civicrm-core/releases{/id}","deployments_url":"https://api.github.com/repos/civicrm/civicrm-core/deployments","created_at":"2013-03-01T06:11:56Z","updated_at":"2016-02-09T16:08:52Z","pushed_at":"2016-02-11T15:10:02Z","git_url":"git://github.com/civicrm/civicrm-core.git","ssh_url":"git@github.com:civicrm/civicrm-core.git","clone_url":"https://github.com/civicrm/civicrm-core.git","svn_url":"https://github.com/civicrm/civicrm-core","homepage":null,"size":129224,"stargazers_count":140,"watchers_count":140,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":371,"mirror_url":null,"open_issues_count":64,"forks":371,"open_issues":64,"watchers":140,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687"},"html":{"href":"https://github.com/civicrm/civicrm-core/pull/7687"},"issue":{"href":"https://api.github.com/repos/civicrm/civicrm-core/issues/7687"},"comments":{"href":"https://api.github.com/repos/civicrm/civicrm-core/issues/7687/comments"},"review_comments":{"href":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687/comments"},"review_comment":{"href":"https://api.github.com/repos/civicrm/civicrm-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/civicrm/civicrm-core/pulls/7687/commits"},"statuses":{"href":"https://api.github.com/repos/civicrm/civicrm-core/statuses/aca3c96890fb23bebc7caed2d894f95e62536ac0"}}}}