Last active
October 1, 2020 14:53
-
-
Save martinvol/403794e02ea4dcbaf8e2e30722ccc118 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Startup { | |
private static async example_payment() { | |
const headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Authorization': 'Basic ' + Buffer.from('sk_test_RNf1bOpZ1h6nN3tOucucRCMs').toString('base64') | |
} | |
// create a customer | |
const customer = await fetch(`https://api.stripe.com/v1/customers`, { | |
method: 'POST', | |
headers: headers, | |
body: "description=hello2" | |
}); | |
const customer_response = await customer.json() | |
console.log(await customer_response) | |
const customer_id = customer_response.id | |
// create a source method | |
const source = await fetch(`https://api.stripe.com/v1/customers/${customer_id}/sources`, { | |
method: 'POST', | |
headers: headers, | |
body: "source=tok_visa" | |
}); | |
const source_response = await source.json() | |
console.log(source_response ) | |
var source_id = source_response.id | |
// charge the method | |
const charge = await fetch(`https://api.stripe.com/v1/charges`, { | |
method: 'POST', | |
headers: headers, | |
body: `amount=2000¤cy=usd&source=${source_id}&customer=${customer_id}&description=My First Test Charge (created for API docs)` | |
}); | |
const data = await charge.json() | |
console.log(data) | |
return data; | |
} | |
} | |
// responses: | |
// customer | |
{ id: 'cus_I7hyoSROFyS1tR', | |
object: 'customer', | |
account_balance: 0, | |
address: null, | |
balance: 0, | |
created: 1601561713, | |
currency: null, | |
default_source: null, | |
delinquent: false, | |
description: 'hello2', | |
discount: null, | |
email: null, | |
invoice_prefix: '03FD2AAA', | |
invoice_settings: | |
{ custom_fields: null, | |
default_payment_method: null, | |
footer: null }, | |
livemode: false, | |
metadata: {}, | |
name: null, | |
next_invoice_sequence: 1, | |
phone: null, | |
preferred_locales: [], | |
shipping: null, | |
sources: | |
{ object: 'list', | |
data: [], | |
has_more: false, | |
total_count: 0, | |
url: '/v1/customers/cus_I7hyoSROFyS1tR/sources' }, | |
subscriptions: | |
{ object: 'list', | |
data: [], | |
has_more: false, | |
total_count: 0, | |
url: '/v1/customers/cus_I7hyoSROFyS1tR/subscriptions' }, | |
tax_exempt: 'none', | |
tax_ids: | |
{ object: 'list', | |
data: [], | |
has_more: false, | |
total_count: 0, | |
url: '/v1/customers/cus_I7hyoSROFyS1tR/tax_ids' }, | |
tax_info: null, | |
tax_info_verification: null } | |
// create method | |
{ id: 'card_1HXSYvIsq0XLweUpiO7QxvU5', | |
object: 'card', | |
address_city: null, | |
address_country: null, | |
address_line1: null, | |
address_line1_check: null, | |
address_line2: null, | |
address_state: null, | |
address_zip: null, | |
address_zip_check: null, | |
brand: 'Visa', | |
country: 'US', | |
customer: 'cus_I7hyoSROFyS1tR', | |
cvc_check: null, | |
dynamic_last4: null, | |
exp_month: 10, | |
exp_year: 2021, | |
fingerprint: 'KoLVoJ9yVwZVENxZ', | |
funding: 'credit', | |
last4: '4242', | |
metadata: {}, | |
name: null, | |
tokenization_method: null } | |
{ id: 'ch_1HXSYwIsq0XLweUp2WZk6M17', | |
object: 'charge', | |
amount: 2000, | |
amount_captured: 2000, | |
amount_refunded: 0, | |
application: null, | |
application_fee: null, | |
application_fee_amount: null, | |
balance_transaction: 'txn_1HXSYwIsq0XLweUpnCWNwWdo', | |
billing_details: | |
{ address: | |
{ city: null, | |
country: null, | |
line1: null, | |
line2: null, | |
postal_code: null, | |
state: null }, | |
email: null, | |
name: null, | |
phone: null }, | |
calculated_statement_descriptor: 'TERAPIAPOINT', | |
captured: true, | |
created: 1601561714, | |
currency: 'usd', | |
customer: 'cus_I7hyoSROFyS1tR', | |
description: 'My First Test Charge (created for API docs)', | |
destination: null, | |
dispute: null, | |
disputed: false, | |
failure_code: null, | |
failure_message: null, | |
fraud_details: {}, | |
invoice: null, | |
livemode: false, | |
metadata: {}, | |
on_behalf_of: null, | |
order: null, | |
outcome: | |
{ network_status: 'approved_by_network', | |
reason: null, | |
risk_level: 'normal', | |
risk_score: 5, | |
seller_message: 'Payment complete.', | |
type: 'authorized' }, | |
paid: true, | |
payment_intent: null, | |
payment_method: 'card_1HXSYvIsq0XLweUpiO7QxvU5', | |
payment_method_details: | |
{ card: | |
{ brand: 'visa', | |
checks: [Object], | |
country: 'US', | |
exp_month: 10, | |
exp_year: 2021, | |
fingerprint: 'KoLVoJ9yVwZVENxZ', | |
funding: 'credit', | |
installments: null, | |
last4: '4242', | |
network: 'visa', | |
three_d_secure: null, | |
wallet: null }, | |
type: 'card' }, | |
receipt_email: null, | |
receipt_number: null, | |
receipt_url: | |
'https://pay.stripe.com/receipts/acct_152TlfIsq0XLweUp/ch_1HXSYwIsq0XLweUp2WZk6M17/rcpt_I7hytG8PAzkMuRrEgxASEAetbC16pmw', | |
refunded: false, | |
refunds: | |
{ object: 'list', | |
data: [], | |
has_more: false, | |
total_count: 0, | |
url: '/v1/charges/ch_1HXSYwIsq0XLweUp2WZk6M17/refunds' }, | |
review: null, | |
shipping: null, | |
source: | |
{ id: 'card_1HXSYvIsq0XLweUpiO7QxvU5', | |
object: 'card', | |
address_city: null, | |
address_country: null, | |
address_line1: null, | |
address_line1_check: null, | |
address_line2: null, | |
address_state: null, | |
address_zip: null, | |
address_zip_check: null, | |
brand: 'Visa', | |
country: 'US', | |
customer: 'cus_I7hyoSROFyS1tR', | |
cvc_check: null, | |
dynamic_last4: null, | |
exp_month: 10, | |
exp_year: 2021, | |
fingerprint: 'KoLVoJ9yVwZVENxZ', | |
funding: 'credit', | |
last4: '4242', | |
metadata: {}, | |
name: null, | |
tokenization_method: null }, | |
source_transfer: null, | |
statement_descriptor: null, | |
statement_descriptor_suffix: null, | |
status: 'succeeded', | |
transfer_data: null, | |
transfer_group: null } | |
// create charge | |
{ id: 'ch_1HXSYwIsq0XLweUp2WZk6M17', | |
object: 'charge', | |
amount: 2000, | |
amount_captured: 2000, // this was pulled from the card. | |
amount_refunded: 0, | |
application: null, | |
application_fee: null, | |
application_fee_amount: null, | |
balance_transaction: 'txn_1HXSYwIsq0XLweUpnCWNwWdo', | |
billing_details: | |
{ address: | |
{ city: null, | |
country: null, | |
line1: null, | |
line2: null, | |
postal_code: null, | |
state: null }, | |
email: null, | |
name: null, | |
phone: null }, | |
calculated_statement_descriptor: 'TERAPIAPOINT', | |
captured: true, | |
created: 1601561714, | |
currency: 'usd', | |
customer: 'cus_I7hyoSROFyS1tR', | |
description: 'My First Test Charge (created for API docs)', | |
destination: null, | |
dispute: null, | |
disputed: false, | |
failure_code: null, | |
failure_message: null, | |
fraud_details: {}, | |
invoice: null, | |
livemode: false, | |
metadata: {}, | |
on_behalf_of: null, | |
order: null, | |
outcome: | |
{ network_status: 'approved_by_network', | |
reason: null, | |
risk_level: 'normal', | |
risk_score: 5, | |
seller_message: 'Payment complete.', | |
type: 'authorized' }, | |
paid: true, | |
payment_intent: null, | |
payment_method: 'card_1HXSYvIsq0XLweUpiO7QxvU5', | |
payment_method_details: | |
{ card: | |
{ brand: 'visa', | |
checks: [Object], | |
country: 'US', | |
exp_month: 10, | |
exp_year: 2021, | |
fingerprint: 'KoLVoJ9yVwZVENxZ', | |
funding: 'credit', | |
installments: null, | |
last4: '4242', | |
network: 'visa', | |
three_d_secure: null, | |
wallet: null }, | |
type: 'card' }, | |
receipt_email: null, | |
receipt_number: null, | |
receipt_url: | |
'https://pay.stripe.com/receipts/acct_152TlfIsq0XLweUp/ch_1HXSYwIsq0XLweUp2WZk6M17/rcpt_I7hytG8PAzkMuRrEgxASEAetbC16pmw', | |
refunded: false, | |
refunds: | |
{ object: 'list', | |
data: [], | |
has_more: false, | |
total_count: 0, | |
url: '/v1/charges/ch_1HXSYwIsq0XLweUp2WZk6M17/refunds' }, | |
review: null, | |
shipping: null, | |
source: | |
{ id: 'card_1HXSYvIsq0XLweUpiO7QxvU5', | |
object: 'card', | |
address_city: null, | |
address_country: null, | |
address_line1: null, | |
address_line1_check: null, | |
address_line2: null, | |
address_state: null, | |
address_zip: null, | |
address_zip_check: null, | |
brand: 'Visa', | |
country: 'US', | |
customer: 'cus_I7hyoSROFyS1tR', | |
cvc_check: null, | |
dynamic_last4: null, | |
exp_month: 10, | |
exp_year: 2021, | |
fingerprint: 'KoLVoJ9yVwZVENxZ', | |
funding: 'credit', | |
last4: '4242', | |
metadata: {}, | |
name: null, | |
tokenization_method: null }, | |
source_transfer: null, | |
statement_descriptor: null, | |
statement_descriptor_suffix: null, | |
status: 'succeeded', | |
transfer_data: null, | |
transfer_group: null } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment