API Contributions and Payments
Each contribution should have one or more payments.

When you are creating contribution using contribution api with completed status a payment is recorded automatically.

If you creating contribution with pending status eg incase of check payments then when you receive payment from bank you use payment api to record payment for the pending contribution


In your case if you recording membership via code then i would suggest you to use Order api where you can pass membership and contribution params in the api params and it will create all required records in one call. You can refer here on how you can use order api to create membership or participant records with its payment in one call.
Cheers
Pradeep