Skip to content

Commit

Permalink
format updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Jul 23, 2024
1 parent e7440b4 commit cc7eb03
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 103 deletions.
3 changes: 2 additions & 1 deletion models/processor/BaseProcessor.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ component accessors="true" {
/**
* Get a new reponse object
*/
function newResponse() provider="ProcessorResponse@cbpayments"{}
function newResponse() provider="ProcessorResponse@cbpayments"{
}

/**
* Retrieve a human readable name for the processor
Expand Down
55 changes: 32 additions & 23 deletions models/processor/StripeProcessor.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* A cool processor/Stripe entity
*/
component
extends ="BaseProcessor"
delegates="DateTime@coreDelegates"
extends ="BaseProcessor"
delegates ="DateTime@coreDelegates"
implements="IPaymentProcessor"
singleton
{
Expand Down Expand Up @@ -81,9 +81,7 @@ component
var processorResponse = variables.stripe.charges.capture( charge_id = arguments.chargeId );

// Capture it baby!
oResponse.setContent(
formatChargeResponse( processorResponse.content )
);
oResponse.setContent( formatChargeResponse( processorResponse.content ) );

// Check for errors
if ( processorResponse.status >= 300 ) {
Expand Down Expand Up @@ -127,9 +125,7 @@ component

var processorResponse = variables.stripe.charges.create( argumentCollection = arguments );
// Charge it baby!
oResponse.setContent(
formatChargeResponse( processorResponse.content )
);
oResponse.setContent( formatChargeResponse( processorResponse.content ) );

// Check for errors
if ( processorResponse.status >= 300 ) {
Expand All @@ -145,6 +141,7 @@ component

/**
* Make a refund on the processor
*
* @charge The identifier of the charge to refund.
* @amount The amount in cents to refund, if not sent then the entire charge is refunded (Optional)
* @reason A reason of why the refund (Optional)
Expand Down Expand Up @@ -214,9 +211,7 @@ component
);

// Create customer
oResponse.setContent(
processorResponse.content
);
oResponse.setContent( processorResponse.content );

// Check for errors
if ( processorResponse.status >= 300 ) {
Expand Down Expand Up @@ -250,7 +245,10 @@ component
log.debug( "Stripe list customers starting: #serializeJSON( arguments )#" );
}

var processorResponse = variables.stripe.customers.list( limit = arguments.limit, offset = arguments.offset );
var processorResponse = variables.stripe.customers.list(
limit = arguments.limit,
offset = arguments.offset
);

// List customers
oResponse.setContent( processorResponse.content );
Expand Down Expand Up @@ -362,11 +360,12 @@ component
ProcessorResponse function cancelSubscription( required subscriptionId, struct metadata = {} ){
var oResponse = newResponse();

var processorResponse = variables.stripe.subscriptions.update( arguments.subscriptionId, { cancel_at_period_end : true } );
// Associate payment method as default
oResponse.setContent(
processorResponse.content
var processorResponse = variables.stripe.subscriptions.update(
arguments.subscriptionId,
{ cancel_at_period_end : true }
);
// Associate payment method as default
oResponse.setContent( processorResponse.content );

// Check for errors
if ( processorResponse.status >= 300 ) {
Expand All @@ -387,7 +386,10 @@ component
ProcessorResponse function resumeSubscription( required subscriptionId, struct metadata = {} ){
var oResponse = newResponse();

var processorResponse = variables.stripe.subscriptions.update( arguments.subscriptionId, { cancel_at_period_end : false } );
var processorResponse = variables.stripe.subscriptions.update(
arguments.subscriptionId,
{ cancel_at_period_end : false }
);

// Associate payment method as default
oResponse.setContent( processorResponse.content );
Expand Down Expand Up @@ -417,12 +419,13 @@ component
){
var oResponse = newResponse();

var processorResponse = variables.stripe.subscriptions.update( arguments.subscriptionId, { quantity : arguments.quantity } );
var processorResponse = variables.stripe.subscriptions.update(
arguments.subscriptionId,
{ quantity : arguments.quantity }
);

// Associate payment method as default
oResponse.setContent(
processorResponse.content
);
oResponse.setContent( processorResponse.content );

// Check for errors
if ( processorResponse.status >= 300 ) {
Expand Down Expand Up @@ -575,7 +578,7 @@ component
{ customer : arguments.providerCustomerId }
).content;

var processorResponse = variables.stripe.customers.update(
var processorResponse = variables.stripe.customers.update(
arguments.providerCustomerId,
{ invoice_settings : { default_payment_method : paymentMethod.id } }
);
Expand Down Expand Up @@ -651,7 +654,13 @@ component
* @epochSeconds
*/
string function fromUnixSeconds( required numeric epochSeconds ){
return getISOTime( dateAdd( "s", arguments.epochSeconds, "1970-01-01T00:00:00Z" ) );
return getISOTime(
dateAdd(
"s",
arguments.epochSeconds,
"1970-01-01T00:00:00Z"
)
);
}

/**
Expand Down
163 changes: 84 additions & 79 deletions test-harness/tests/resources/BaseProcessorTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,31 @@ component extends="coldbox.system.testing.BaseTestCase" {

expect( response.getError() ).toBeFalse();
expect( response.getContent().paid ).toBeTrue();
expect( response.getContent() ).toBeStruct()
.toHaveKey( "id" )
.toHaveKey( "object" )
.toHaveKey( "amount" )
.toHaveKey( "amount_captured" )
.toHaveKey( "amount_refunded" )
.toHaveKey( "balance_transaction" )
.toHaveKey( "billing_details" )
.toHaveKey( "processor" )
.toHaveKey( "captured" )
.toHaveKey( "created" )
.toHaveKey( "currency" )
.toHaveKey( "disputed" )
.toHaveKey( "fraud_details" )
.toHaveKey( "livemode" )
.toHaveKey( "metadata" )
.toHaveKey( "outcome" )
.toHaveKey( "paid" )
.toHaveKey( "payment_method" )
.toHaveKey( "payment_method_details" )
.toHaveKey( "receipt_url" )
.toHaveKey( "refunded" )
.toHaveKey( "status" );
variables.testCharge = response.getContent().id;
expect( response.getContent() )
.toBeStruct()
.toHaveKey( "id" )
.toHaveKey( "object" )
.toHaveKey( "amount" )
.toHaveKey( "amount_captured" )
.toHaveKey( "amount_refunded" )
.toHaveKey( "balance_transaction" )
.toHaveKey( "billing_details" )
.toHaveKey( "processor" )
.toHaveKey( "captured" )
.toHaveKey( "created" )
.toHaveKey( "currency" )
.toHaveKey( "disputed" )
.toHaveKey( "fraud_details" )
.toHaveKey( "livemode" )
.toHaveKey( "metadata" )
.toHaveKey( "outcome" )
.toHaveKey( "paid" )
.toHaveKey( "payment_method" )
.toHaveKey( "payment_method_details" )
.toHaveKey( "receipt_url" )
.toHaveKey( "refunded" )
.toHaveKey( "status" );
variables.testCharge = response.getContent().id;
} );

it( "can make a test preAuth", function(){
Expand All @@ -90,67 +91,71 @@ component extends="coldbox.system.testing.BaseTestCase" {

expect( response.getError() ).toBeFalse();
expect( response.getContent().paid ).toBeTrue();
expect( response.getContent() ).toBeStruct()
.toHaveKey( "id" )
.toHaveKey( "object" )
.toHaveKey( "amount" )
.toHaveKey( "amount_captured" )
.toHaveKey( "amount_refunded" )
.toHaveKey( "billing_details" )
.toHaveKey( "processor" )
.toHaveKey( "captured" )
.toHaveKey( "created" )
.toHaveKey( "currency" )
.toHaveKey( "disputed" )
.toHaveKey( "fraud_details" )
.toHaveKey( "livemode" )
.toHaveKey( "metadata" )
.toHaveKey( "outcome" )
.toHaveKey( "paid" )
.toHaveKey( "payment_method" )
.toHaveKey( "payment_method_details" )
.toHaveKey( "receipt_url" )
.toHaveKey( "refunded" )
.toHaveKey( "status" );
expect( response.getContent().captured ).toBeFalse();
expect( structKeyExists( response.getContent(), "balance_transaction" ) ).toBeFalse();
variables.testPreAuth = response.getContent().id;
expect( response.getContent() )
.toBeStruct()
.toHaveKey( "id" )
.toHaveKey( "object" )
.toHaveKey( "amount" )
.toHaveKey( "amount_captured" )
.toHaveKey( "amount_refunded" )
.toHaveKey( "billing_details" )
.toHaveKey( "processor" )
.toHaveKey( "captured" )
.toHaveKey( "created" )
.toHaveKey( "currency" )
.toHaveKey( "disputed" )
.toHaveKey( "fraud_details" )
.toHaveKey( "livemode" )
.toHaveKey( "metadata" )
.toHaveKey( "outcome" )
.toHaveKey( "paid" )
.toHaveKey( "payment_method" )
.toHaveKey( "payment_method_details" )
.toHaveKey( "receipt_url" )
.toHaveKey( "refunded" )
.toHaveKey( "status" );
expect( response.getContent().captured ).toBeFalse();
expect( structKeyExists( response.getContent(), "balance_transaction" ) ).toBeFalse();
variables.testPreAuth = response.getContent().id;
} );

it( "Can capture a pre-authorization", function(){
if( !variables.keyExists( "testPreAuth" ) ){
variables.testPreAuth = variables.model.preAuthorize(
amount = 100,
source = "tok_visa",
description = "Unit test charge"
).getContent().id;
if ( !variables.keyExists( "testPreAuth" ) ) {
variables.testPreAuth = variables.model
.preAuthorize(
amount = 100,
source = "tok_visa",
description = "Unit test charge"
)
.getContent()
.id;
}
var response = variables.model.capture( variables.testPreAuth );

expect( response.getContent() ).toBeStruct()
.toHaveKey( "id" )
.toHaveKey( "object" )
.toHaveKey( "amount" )
.toHaveKey( "amount_captured" )
.toHaveKey( "amount_refunded" )
.toHaveKey( "balance_transaction" )
.toHaveKey( "billing_details" )
.toHaveKey( "processor" )
.toHaveKey( "captured" )
.toHaveKey( "created" )
.toHaveKey( "currency" )
.toHaveKey( "disputed" )
.toHaveKey( "fraud_details" )
.toHaveKey( "livemode" )
.toHaveKey( "metadata" )
.toHaveKey( "outcome" )
.toHaveKey( "paid" )
.toHaveKey( "payment_method" )
.toHaveKey( "payment_method_details" )
.toHaveKey( "receipt_url" )
.toHaveKey( "refunded" )
.toHaveKey( "status" );

expect( response.getContent() )
.toBeStruct()
.toHaveKey( "id" )
.toHaveKey( "object" )
.toHaveKey( "amount" )
.toHaveKey( "amount_captured" )
.toHaveKey( "amount_refunded" )
.toHaveKey( "balance_transaction" )
.toHaveKey( "billing_details" )
.toHaveKey( "processor" )
.toHaveKey( "captured" )
.toHaveKey( "created" )
.toHaveKey( "currency" )
.toHaveKey( "disputed" )
.toHaveKey( "fraud_details" )
.toHaveKey( "livemode" )
.toHaveKey( "metadata" )
.toHaveKey( "outcome" )
.toHaveKey( "paid" )
.toHaveKey( "payment_method" )
.toHaveKey( "payment_method_details" )
.toHaveKey( "receipt_url" )
.toHaveKey( "refunded" )
.toHaveKey( "status" );
} );

it( "Will error on a fake refund", function(){
Expand Down

0 comments on commit cc7eb03

Please sign in to comment.