Balanced payments API doubts - python

I'm trying to integrate balanced payments API into my work. I've looked at Docs and other concerned forums also but didn't get clear my doubts.
I understand the flow of this though, but due to some method names i'm getting confused.
e.g. customer.
https://docs.balancedpayments.com/1.0/overview/getting-started/#charge-a-credit-card
What have I tried till now:(in Python)
I've created a dummy/Test bank and it's working fine.
bank_account = balanced.BankAccount(...) but I dont know how much could I debit from this or first do I have to credit into.
after this I created a card and then I created a customer customer = balanced.Customer().save()
and then associated the card with the customer customer.add_card('/v1/marketplaces/TEST-MP52IlCmywk6hGbgS75QSlN/cards/CC3AiMy0KEP1PhwnffMk32RF')
but how is this statement working?
customer.add_bank_account('/v1/bank_accounts/BA24Zc2jo1moflunJDxKrCrB')
I'm slightly confused with this customer word.
Could somebody please explain this from beginning in simple steps.

Customers are objects that represent businesses or people within your marketplace (i.e. buyers and sellers). In this revision of the API, funding instruments (e.g. credit cards, bank accounts) must be associated to a specific customer object before you can initiate any transactions.
The method you listed:
customer.add_bank_account('/v1/bank_accounts/BA24Zc2jo1moflunJDxKrCrB')
Is associating the bank account to the customer object that you created.
You specify the amount for a debit (charge) or credit (payout). The limit depends on a number of factors (e.g. credit limit, available funds, transaction limits)

Related

How to model an financial accounting system in Django?

The Django application I'm developing for a taxi company has following modules,
Trips
Customers (who buy products)
Vehicles
Drivers
Each trip is constituted by selecting a customer, a vehicle and a driver along with a few other parameters.
I will be recording every single trip, and the revenue generated because of it.
I also would like to assign this revenue generated to the individual customer who took the vehicle, and to the vehicle which was used in the trip. Since I would like to have a deeper understanding of the customer's spending and the revenue generated by vehicles.
I need to have an Accounts Receivables and a Received statement for each trip.
Is there a standard way to achieve this? I believe a similar approach is used in typical e-commerce systems. Any and every help is appreciated.
Edit 1
I believe I can record all the transactions in this way. Since a trip already contains vehicles and customers, probably I can derive the respective transactions to them.

python json data in tuple format not parsable

I'm having a hard time understanding why the following output, which is supposed to be json format, and is generated from a datbase query, isnt parsable.
dbresponse = """
(('{"stopApprovalInd":true,"nonPersonalizedCardLine3":"Valued Cardholder","productRoutingBins":[{"requestType":"DIGITAL_ACCOUNT_REQUEST","bin":"342010002"}],"holdtimeSeconds":0,"defaultUpcInd":"false","updatedTimestamp":"2019-01-23T18:53:26.261Z","productName":"PB EGIFT (CAG) MAYO\'S $100","reloadMaxAmount":0,"issuerCompanyCode":"BKPB","updaterId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","sellStartDate":"2018-08-20T00:00:00.000+0000","taxIncludedInd":false,"taxPercent":0,"maxValueAmount":100,"proxyCardLength":19,"inventorySource":"BLAST","postReversalInd":false,"distributionChannel":"DIGITAL","multicardFlag":"N","companyCode":"BKPB","indentDataType":"0","activateOnShipment":"false","productRedemptionMethods":[],"upc":"07675030446","productFees":[{"feeAmount":0,"feeType":"PURCHASE"},{"feeAmount":0,"feeType":"TRANSACTION"},{"feeAmount":0,"feeType":"CUSTOMIZATION"}],"cpDivisionId":"2X2A9M5KRLXQWQ1SB","subGroupId":"YVAAN33PV7MZ3Z49V0F0J","defaultProductConfigurationId":"Y56X4RXNCY2R9ACSDH","isContentEnabled":false,"productFulfillments":[{"fulfillmentMethod":"EMAIL","fulfillmentType":"PRINT_ON_DEMAND"}],"taxAmount":0,"redeemLocationInd":false,"taxableInd":false,"productRedemptionLocations":[],"generationType":"0","serviceCode":"121","processorCompanyCode":"HP","productDisplayname":"MAYO\'s $100 eGift","baseValueAmount":100,"creatorId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","subsequentActivation":false,"generateProxyCardNumberInd":false,"productCategory":"CLOSELOOP","exclusionInd":false,"reloadableInd":false,"reversibleInd":false,"productLocale":[{"redemptionInstructions":"<p>Your E-gift Card is redeemable online at mayo.com and in \'s stores nationwide.<\\/p>","productTemplates":[{"templateType":"PRODUCTION","templateId":"Z6WSTWN9HABX8","templatePath":"https://blahblah.net/gcmimages/View/WGNX8/index.html"}],"localeCode":"en_US","inStoreInstructions":"<p>In Store: Print this entire page, and present it to a Mayo\'s Associate at checkout.<\\/p>","onlineInstructions":"<p>Online: Enter your E-Gift Card Number at checkout in the PAY WITH GIFT CARD box. If you have any questions, or to check your balance, please call 1-800-511-2752.<br>You may also scan your printed barcode at a price checker terminal in stores.<br>Your Mayo\'s E-Gift Card number is required for all inquiries.<\\/p>","productDescription":"Mayo\'s, the largest retail brand of Mayo\'s, Inc. (NYSE:M), delivers fashion and affordable luxury to customers at approximately 670 locations in 45 states, the District of Columbia, Puerto Rico and Guam, as well as to customers in the U.S. and more than 100 international destinations through its leading online store at macys.com. Via its stores, e-commerce site, mobile and social platforms, Mayo\'s offers distinctive assortments including the most desired family of exclusive and fashion brands for him, her and home. Mayo\'s is known for such epic events as Mayo\'s 4th of July Fireworks\xae and the Mayo\'s Thanksgiving Day Parade\xae. Building on a more than 150-year tradition, and with the collective support of customers and employees, Mayo\'s helps strengthen communities by supporting local and national charities giving more than $69 million each year to help make a difference in the lives of our customers","termsAndConditions":"Your Mayo\'s E-Gift Card number may be used to purchase any merchandise on-line at macys.com or in-store by following the instructions in the E-Gift Card email. You may not add value back onto the E-Gift Card, nor redeem it for cash or apply it as payment or credit to your credit card account. When you make a purchase with your E-Gift Card number, the value of your purchase plus any shipping/handling fees and sales tax, if applicable, will be automatically deducted from your \\"open to buy.\\" You may check any remaining value via the online Balance Inquiry function, or in-store by scanning the barcode at a price checker terminal or by calling 1-800-511-2752. Please safeguard your Mayo\'s E-Gift Card number. The bearer is responsible for its loss or theft. If your E-Gift Card is lost or stolen, and you have proof of purchase, we will issue you a replacement for the balance shown on our records. Your macys.com E-Gift Card number is required for all inquiries."}],"cardExpirationType":"0","productBarcodes":[{"barcodeType":"1D-CA128"}],"feeStrippingInd":false,"productLineId":"3G2D6R3YG85WZ570","createdTimestamp":"2018-08-20T18:53:46.435Z","inventoryLoadType":"HOT","variableInd":false,"isForcedResponseProduct":false,"reloadMinAmount":0,"entityId":"6APACRYFLXTLSKS","itemBuyerGroupId":"FASHION","provisioningType":"DIGITAL","productFulfillmentPartners":[],"currencyCode":"USD","proxyBin":"0"}',),)
"""
I cant treat it like a json because when I do a type(dbresponse) on the data (directly from the database), python tells me its a "tuple" data. But I know in order for me to be able to access the values, python needs to see the data as a dict.
I have tried converting it multiple different ways, all to no avail.
str(dbresponse)
eval(dict(dbresponse))
str(list(dbresponse)) # tried to convert it to a list, then to a str in hopes of then being able to convert it to dictionary. didnt work.
I dont know much about json.
My question is, is there a foolproof way to turn/convert the above data from tuple to dictionary? And once that is done, how do i iterate through all the keys/values in the data so I see what is available.
I tried pprinnt (pretty print) but that isn't so clear to me (i could be using it incorrectly).
If your response really is a string as shown here, and always has the same format, you could remove the ((' at the start and ',),) at the end. The rest is a valid JSON string:
import json
dbresponse = """(('{"stopApprovalInd":true,"nonPersonalizedCardLine3":"Valued Cardholder","productRoutingBins":[{"requestType":"DIGITAL_ACCOUNT_REQUEST","bin":"342010002"}],"holdtimeSeconds":0,"defaultUpcInd":"false","updatedTimestamp":"2019-01-23T18:53:26.261Z","productName":"PB EGIFT (CASHSTAR) MACY\'S $100","reloadMaxAmount":0,"issuerCompanyCode":"BKPB","updaterId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","sellStartDate":"2018-08-20T00:00:00.000+0000","taxIncludedInd":false,"taxPercent":0,"maxValueAmount":100,"proxyCardLength":19,"inventorySource":"BLAST","postReversalInd":false,"distributionChannel":"DIGITAL","multicardFlag":"N","companyCode":"BKPB","indentDataType":"0","activateOnShipment":"false","productRedemptionMethods":[],"upc":"07675030446","productFees":[{"feeAmount":0,"feeType":"PURCHASE"},{"feeAmount":0,"feeType":"TRANSACTION"},{"feeAmount":0,"feeType":"CUSTOMIZATION"}],"cpDivisionId":"2X2A9M5KRLXQWQ1SB","subGroupId":"YVAAN33PV7MZ3Z49V0F0J","defaultProductConfigurationId":"Y56X4RXNCY2R9ACSDH","isContentEnabled":false,"productFulfillments":[{"fulfillmentMethod":"EMAIL","fulfillmentType":"PRINT_ON_DEMAND"}],"taxAmount":0,"redeemLocationInd":false,"taxableInd":false,"productRedemptionLocations":[],"generationType":"0","serviceCode":"121","processorCompanyCode":"HP","productDisplayname":"Macy\'s $100 eGift","baseValueAmount":100,"creatorId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","subsequentActivation":false,"generateProxyCardNumberInd":false,"productCategory":"CLOSELOOP","exclusionInd":false,"reloadableInd":false,"reversibleInd":false,"productLocale":[{"redemptionInstructions":"<p>Your E-gift Card is redeemable online at macys.com and in Macy\'s stores nationwide.<\\/p>","productTemplates":[{"templateType":"PRODUCTION","templateId":"Z6WSTWN9HABX8","templatePath":"https://blahblah.net/gcmimages/View/WGNX8/index.html"}],"localeCode":"en_US","inStoreInstructions":"<p>In Store: Print this entire page, and present it to a Macy\'s Associate at checkout.<\\/p>","onlineInstructions":"<p>Online: Enter your E-Gift Card Number at checkout in the PAY WITH GIFT CARD box. If you have any questions, or to check your balance, please call 1-800-511-2752.<br>You may also scan your printed barcode at a price checker terminal in stores.<br>Your Macy\'s E-Gift Card number is required for all inquiries.<\\/p>","productDescription":"Macy\'s, the largest retail brand of Macy\'s, Inc. (NYSE:M), delivers fashion and affordable luxury to customers at approximately 670 locations in 45 states, the District of Columbia, Puerto Rico and Guam, as well as to customers in the U.S. and more than 100 international destinations through its leading online store at macys.com. Via its stores, e-commerce site, mobile and social platforms, Macy\'s offers distinctive assortments including the most desired family of exclusive and fashion brands for him, her and home. Macy\'s is known for such epic events as Macy\'s 4th of July Fireworks\xae and the Macy\'s Thanksgiving Day Parade\xae. Building on a more than 150-year tradition, and with the collective support of customers and employees, Macy\'s helps strengthen communities by supporting local and national charities giving more than $69 million each year to help make a difference in the lives of our customers","termsAndConditions":"Your Macy\'s E-Gift Card number may be used to purchase any merchandise on-line at macys.com or in-store by following the instructions in the E-Gift Card email. You may not add value back onto the E-Gift Card, nor redeem it for cash or apply it as payment or credit to your credit card account. When you make a purchase with your E-Gift Card number, the value of your purchase plus any shipping/handling fees and sales tax, if applicable, will be automatically deducted from your \\"open to buy.\\" You may check any remaining value via the online Balance Inquiry function, or in-store by scanning the barcode at a price checker terminal or by calling 1-800-511-2752. Please safeguard your Macy\'s E-Gift Card number. The bearer is responsible for its loss or theft. If your E-Gift Card is lost or stolen, and you have proof of purchase, we will issue you a replacement for the balance shown on our records. Your macys.com E-Gift Card number is required for all inquiries."}],"cardExpirationType":"0","productBarcodes":[{"barcodeType":"1D-CA128"}],"feeStrippingInd":false,"productLineId":"3G2D6R3YG85WZ570","createdTimestamp":"2018-08-20T18:53:46.435Z","inventoryLoadType":"HOT","variableInd":false,"isForcedResponseProduct":false,"reloadMinAmount":0,"entityId":"6APACRYFLXTLSKS","itemBuyerGroupId":"FASHION","provisioningType":"DIGITAL","productFulfillmentPartners":[],"currencyCode":"USD","proxyBin":"0"}',),)"""
json_str = dbresponse[3:-5]
data = json.loads(json_str)
print(data)
# {'stopApprovalInd': True, 'nonPersonalizedCardLine3': 'Valued Cardholder', 'productRoutingBins': [{'requestType': 'DIGITAL_ACCOUNT_REQUEST', 'bin': '342010002'}], 'holdtimeSeconds': 0, 'defaultUpcInd': 'false', 'updatedTimestamp': '2019-01-23T18:53:26.261Z', 'productName': "PB EGIFT (CASHSTAR) MACY'S $100", 'reloadMaxAmount': 0, 'issuerCompanyCode': ...
print(data['stopApprovalInd'])
# True
The inner content seems to be wrapped in single quote ', but contains unescaped single quotes (e.g. "MAYO'S"). This of course is a syntax error.
Despite the several levels of escaping seems the code that generated the content still isn't able to get it right.
As Thierry found however removing the first 4 and last 6 characters leaves a valid JSON (in this case) and you can parse it with json.loads(dbresponse[4:-6]).
For support other types of inputs we can use find and rfind:
import json
# dbresponse = ...
begin = dbresponse.find("'")
end = dbresponse.rfind("'")
data = json.loads(dbresponse[begin+1:end])

Django - How can I manage custom payments between users on my platform with Stripe?

I'm trying to create a platform with multiple functionalities, and one of them is a crowfunding of projects, in which the users can post a project and ask for funds. (like kickstarter or indiegogo).
I'm working with Django 2.0, Python 3.6 and PostgreSQL and I want to use Stripe for payments. I also read a bunch of the Stripe's API Documentation, and I have some ideas for doing this, but this will be my first API implementation so I would like to do it well (more even talking about payment systems).
The main question is: How can I do that multiple users realize payments to another for one project ONLY when the goals of that project are reached?
What I think that is the better is to use (Stripe Connect) Express/Custom Accounts to create an account for each user that posts a Project, so I can redirect all the payments to that account.
The thing is that I also want to apply a fee for my platform.
And I don't know exactly how can I do this. I imagine that Stripe give an option for that to evade doing two transactions in my own backend (one for the project's user and another for the platform (me).
Then I have another related problem that is when should I do the transactions?
I have to asure the 100% of the transactions, but also that the project get the funds only when it reach the goals, So I don't know if with Stripe I can freeze all the funds and then give it to the project or refund it depending on the state of the project goals.
As an alternative comes to my mind to put all the funds to an a sub-bank account of my own platform and then if the project reach the funds, do the transaction to the user's account; or if the project fails, make a full refund. The problem I see here is that if the project succeed, Stripe get's x2 times a transaction commission, and if the project fails, I (my platform) have to pay for my own the first transaction's Stripe commission. So this is not t.he correct answer at all.
Kickstarter (as a main example) only do the transaction when the
project reach the funding goals, but doing that, they can (and
usually) get some failed transactions. This is what I cannot accept in
my platform.
To sum up, I want be able to make that an user can pay to another only when the project goals are reached, get a commission for it and asure that the 100% of the transactions are accepted.
I would like to ask for help in the coding (or tips at least) because I also read the documentation of dj-stripe and pinax-stripe, but I don't see the way of doing what I need because their documentation is based on simple payments always to the same user and for subscriptions.
I think that maybe the best option is to use the python api given by Stripe.
I also searched a lot for this and found the following things: Crowdao, a project with stripe integrated for crowdfunding BUT is only for one project, so it doesn't solve the problem; A way of doing AHC with Django-allauth and Stripe, but I don't see exactly how they do that, and I want to use more payment systems too, so I imagine it doesn't fit as a good answer for my problem.
If you need any extra information please ask for it, I'll do whatever I can. Thank you very much.
You could use stripe connect and when creating the charge use authorize-only (Note: Max 7 days)
As #Oscar has suggested, connect[0] is the way to go.
So basically yourself will registered as a platform account and each projects will be registered as connected account, most likely custom/express type[1]. Your end user accounts who is contributing to each projects will live in your main platform account.
There are many ways to achieve your goal by charging the customer when goal is met. but One way is that So you can do a Destination Charge [2] and a Manual Payout[3].
Basically
In Destination charge, you charge the user $100 and transfer $80 to the connected project account; so you keep $20 as a fee;
The $80 sits on the project stripe account's balance which is not paid out to their bank account.
If the goal reaches, you trigger a manual payout to the project so that the project actually get the $80 dollars
If not, you will need to perform on refund[4] on all the transactions on that project.
That's it.
Take note the manual payout only hold for 90 days, after that it moves out directly
Your account will bear all the fees to Stripe for transactions which you can recover from your application fee ($20) on the project.
But the refund will cost you as there will be no fee earned but still payable to Stripe.
Hope it helps.
0 connect
1 accounts
2 Destination Charge
3 Manual Payouts
4 Refund

How to buy a product using a various payments methods in python?

I have a project that am working in and it almost done except one problem that i can't make or in fact i don't know how to make it done .
The client told me that he want to connect a various payments methods to his site , so lets consider that you are a user and you want to buy a product , inside your panel as a user there is a various banks or methods to buy this product, lets say:
Qiwi wallet
Webmoney
Visa Card
Master Card
Yandex money
you can choose anyone of these to buy it .
Another thing is to show your balance inside the panel so to know whether you have enough money to pay or not, also he want that the user could charge money into his balance if he didn't have enough money.
There is a service called Stripe, which provide stuffs like that, but i 'am not really sure if it would help in any way, all i know about it is, you can make any payments using Master card or Visa card that's all .
Simply the issue is to know how to, pay with various payments methods, balance status and charge balance.
The project is written in python using Flask framework .
Please Please Please , bagging you all, how to make that work, or in a different way from where to start ?, which process should i follow ?, any help really truly would be tons appreciated .
Stripe actually provides quite a number of payment methods but not all of the ones you've listed, so Stripe can definitely help, but you're going to have to implement multiple payment flows here - one for the methods that Stripe can handle, and one for each of the others - as part of your application.
With regards to the Stripe stuff, I'd suggest you have a read through the documentation to learn about getting started there.

Provide discount to preferred customer with Satchmo?

I am new to Satchmo -- picked it up because I needed payment processing for site subscriptions and physical product.
My site will have two classes of users: paid subscribers and free users. Both can order a
physical product. Paid subscribers get an automatic discount on all orders.
I don't see a configuration for this in the admin. (Discount looks like it would apply to all users. If I'm missing something here, let me know.)
So what's the best place to automatically override the price depending on the user class? The displayed price should show up, say, 10% less for subscribers everywhere in the site, not just at the checkout.
Thanks.
Checkout the tiered pricing module

Categories