-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to update a charge #119
Open
chrisnharvey
wants to merge
3
commits into
thephpleague:master
Choose a base branch
from
chrisnharvey:feature/update-charge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* Stripe Update Charge Request. | ||
*/ | ||
namespace Omnipay\Stripe\Message; | ||
|
||
/** | ||
* Stripe Update Charge Request. | ||
* | ||
* @see \Omnipay\Stripe\Gateway | ||
* @link https://stripe.com/docs/api/charges/update | ||
*/ | ||
class UpdateChargeRequest extends AuthorizeRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('transactionReference'); | ||
|
||
$data = array(); | ||
|
||
if ($this->getDescription()) { | ||
$data['description'] = $this->getDescription(); | ||
} | ||
|
||
if ($this->getCustomerReference()) { | ||
$data['customer'] = $this->getCustomerReference(); | ||
} | ||
|
||
if ($this->getMetadata()) { | ||
$data['metadata'] = $this->getMetadata(); | ||
} | ||
|
||
if ($this->getReceiptEmail()) { | ||
$data['receipt_email'] = $this->getReceiptEmail(); | ||
} | ||
|
||
if ($this->getTransferGroup()) { | ||
$data['transfer_group'] = $this->getTransferGroup(); | ||
} | ||
|
||
// Filter out the empty/non-updated values | ||
return $data; | ||
} | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->endpoint.'/charges/'.$this->getTransactionReference(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
use Omnipay\Tests\TestCase; | ||
|
||
class UpdateChargeRequestTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->request = new UpdateChargeRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->setTransactionReference('foo'); | ||
} | ||
|
||
public function testEndpoint() | ||
{ | ||
$this->assertSame('https://api.stripe.com/v1/charges/foo', $this->request->getEndpoint()); | ||
} | ||
|
||
public function testData() | ||
{ | ||
$this->request->setDescription('New customer'); | ||
$this->request->setCustomerReference('cus_1MZeNih5LdKxDq'); | ||
$this->request->setReceiptEmail('[email protected]'); | ||
$this->request->setTransferGroup('test'); | ||
$this->request->setMetadata(array('field' => 'value')); | ||
|
||
$data = $this->request->getData(); | ||
|
||
$this->assertSame('cus_1MZeNih5LdKxDq', $data['customer']); | ||
$this->assertSame('[email protected]', $data['receipt_email']); | ||
$this->assertSame('New customer', $data['description']); | ||
$this->assertArrayHasKey('field', $data['metadata']); | ||
$this->assertSame('value', $data['metadata']['field']); | ||
$this->assertSame('test', $data['transfer_group']); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('UpdateChargeSuccess.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertSame('ch_1E0Pt92eZvKYlo2C05QSmQvw', $response->getTransactionReference()); | ||
$this->assertSame('cus_1MZeNih5LdKxDq', $response->getCustomerReference()); | ||
$this->assertNull($response->getMessage()); | ||
} | ||
|
||
public function testSendFailure() | ||
{ | ||
$this->setMockHttpResponse('UpdateChargeFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertNull($response->getTransactionReference()); | ||
$this->assertNull($response->getCustomerReference()); | ||
$this->assertSame('No such charge: ch_1E0Pt92eZvKYlo2C0QSmQvw', $response->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
HTTP/1.1 400 Bad Request | ||
Server: nginx | ||
Date: Sun, 05 May 2013 08:52:09 GMT | ||
Content-Type: application/json;charset=utf-8 | ||
Content-Length: 127 | ||
Connection: keep-alive | ||
Cache-Control: no-cache, no-store | ||
Access-Control-Max-Age: 300 | ||
Access-Control-Allow-Credentials: true | ||
|
||
{ | ||
"error": { | ||
"code": "resource_missing", | ||
"doc_url": "https://stripe.com/docs/error-codes/resource-missing", | ||
"message": "No such charge: ch_1E0Pt92eZvKYlo2C0QSmQvw", | ||
"param": "id", | ||
"type": "invalid_request_error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
HTTP/1.1 200 OK | ||
Server: nginx | ||
Date: Sun, 05 May 2013 08:51:15 GMT | ||
Content-Type: application/json;charset=utf-8 | ||
Content-Length: 997 | ||
Connection: keep-alive | ||
Cache-Control: no-cache, no-store | ||
Access-Control-Max-Age: 300 | ||
Access-Control-Allow-Credentials: true | ||
|
||
{ | ||
"id": "ch_1E0Pt92eZvKYlo2C05QSmQvw", | ||
"object": "charge", | ||
"amount": 1000, | ||
"amount_refunded": 0, | ||
"application": null, | ||
"application_fee": null, | ||
"application_fee_amount": null, | ||
"balance_transaction": "txn_19XJJ02eZvKYlo2ClwuJ1rbA", | ||
"captured": false, | ||
"created": 1549357603, | ||
"currency": "usd", | ||
"customer": "cus_1MZeNih5LdKxDq", | ||
"description": "Test", | ||
"destination": null, | ||
"dispute": null, | ||
"failure_code": "card_declined", | ||
"failure_message": "Your card was declined.", | ||
"fraud_details": {}, | ||
"invoice": null, | ||
"livemode": false, | ||
"metadata": {}, | ||
"on_behalf_of": null, | ||
"order": null, | ||
"outcome": { | ||
"network_status": "not_sent_to_network", | ||
"reason": "highest_risk_level", | ||
"risk_level": "highest", | ||
"risk_score": 96, | ||
"rule": "block_if_high_risk", | ||
"seller_message": "Stripe blocked this payment as too risky.", | ||
"type": "blocked" | ||
}, | ||
"paid": false, | ||
"payment_intent": null, | ||
"payment_method": null, | ||
"payment_method_details": { | ||
"card": { | ||
"brand": "Visa", | ||
"country": "US", | ||
"dynamic_last4": null, | ||
"exp_month": 12, | ||
"exp_year": 2031, | ||
"fingerprint": "yTFMYiPXiPa5AoSn", | ||
"funding": "credit", | ||
"last4": "4954", | ||
"three_d_secure": null | ||
}, | ||
"type": "card" | ||
}, | ||
"receipt_email": null, | ||
"receipt_number": "1431-2893", | ||
"receipt_url": "https://pay.stripe.com/receipts/acct_1032D82eZvKYlo2C/ch_1E0Pt92eZvKYlo2C05QSmQvw/rcpt_ETMcXQkHm68RMJztwqc6DDKAdCm8QR7", | ||
"refunded": false, | ||
"refunds": { | ||
"object": "list", | ||
"data": [], | ||
"has_more": false, | ||
"total_count": 0, | ||
"url": "/v1/charges/ch_1E0Pt92eZvKYlo2C05QSmQvw/refunds" | ||
}, | ||
"review": null, | ||
"shipping": null, | ||
"source": { | ||
"id": "card_1E0Pt52eZvKYlo2Czz19lZi3", | ||
"object": "card", | ||
"address_city": null, | ||
"address_country": null, | ||
"address_line1": null, | ||
"address_line1_check": null, | ||
"address_line2": null, | ||
"address_state": null, | ||
"address_zip": "12345", | ||
"address_zip_check": "unavailable", | ||
"brand": "Visa", | ||
"country": "US", | ||
"customer": null, | ||
"cvc_check": "unavailable", | ||
"dynamic_last4": null, | ||
"exp_month": 12, | ||
"exp_year": 2031, | ||
"fingerprint": "yTFMYiPXiPa5AoSn", | ||
"funding": "credit", | ||
"last4": "4954", | ||
"metadata": {}, | ||
"name": "[email protected]", | ||
"tokenization_method": null | ||
}, | ||
"source_transfer": null, | ||
"statement_descriptor": null, | ||
"status": "failed", | ||
"transfer_data": null, | ||
"transfer_group": null | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type should be
* @return \Omnipay\Stripe\Message\UpdateChargeRequest